diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f9ebf8a4cde..3262a563f4c 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1000,7 +1000,7 @@ class Commande extends CommonOrder $this->db->begin(); - // get extrafields so they will be clone + // get lines so they will be clone foreach($this->lines as $line) $line->fetch_optionals($line->rowid); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 53de8e56eb8..a9edc715b3e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5030,57 +5030,6 @@ abstract class CommonObject } } - /** - * Load an object from its id and create a new one in database - * - * @param User $user User that creates - * @param int $fromid Id of object to clone - * @return int New id of clone - */ - public function createFromCloneCommon(User $user, $fromid) - { - global $user, $langs; - - $error = 0; - - dol_syslog(__METHOD__, LOG_DEBUG); - - $object = new self($this->db); - - $this->db->begin(); - - // Load source object - $object->fetchCommon($fromid); - // Reset some properties - unset($object->id); - unset($object->fk_user_creat); - unset($object->import_key); - - // Clear fields - $object->ref = "copy_of_".$object->ref; - $object->title = $langs->trans("CopyOf")." ".$object->title; - // ... - - // Create clone - $result = $object->createCommon($user); - - // Other options - if ($result < 0) { - $error++; - $this->error = $object->error; - $this->errors = $object->errors; - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); - } - - // End - if (!$error) { - $this->db->commit(); - return $object->id; - } else { - $this->db->rollback(); - return -1; - } - } /** * Load object in memory from the database diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index daee7fcc879..6d35404140d 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -142,6 +142,55 @@ class MyObject extends CommonObject return $this->createCommon($user, $notrigger); } + /** + * Clone and object into another one + * + * @param User $user User that creates + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + public function createFromClone(User $user, $fromid) + { + global $hookmanager, $langs; + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); + + $this->db->begin(); + + // Load source object + $object->fetchCommon($fromid); + // Reset some properties + unset($object->id); + unset($object->fk_user_creat); + unset($object->import_key); + + // Clear fields + $object->ref = "copy_of_".$object->ref; + $object->title = $langs->trans("CopyOf")." ".$object->title; + // ... + + // Create clone + $object->context['createfromclone'] = 'createfromclone'; + $result = $object->createCommon($user); + if ($result < 0) { + $error++; + $this->error = $object->error; + $this->errors = $object->errors; + } + + // End + if (!$error) { + $this->db->commit(); + return $object->id; + } else { + $this->db->rollback(); + return -1; + } + } + /** * Load object in memory from the database * @@ -151,7 +200,25 @@ class MyObject extends CommonObject */ public function fetch($id, $ref = null) { - return $this->fetchCommon($id, $ref); + $result = $this->fetchCommon($id, $ref); + if ($result > 0 && ! empty($this->table_element_line)) $this->fetch_lines(); + return $result; + } + + /** + * Load object lines in memory from the database + * + * @param int $id Id object + * @param string $ref Ref + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetch_lines($id, $ref = null) + { + $this->lines=array(); + + // Load lines with object MyObjectLine + + return count($this->lines)?1:0; } /** @@ -368,20 +435,16 @@ class MyObject extends CommonObject } /** - * Class MyModuleObjectLine + * Class MyObjectLine. You can also remove this and generate a CRUD class for lines objects. */ -class MyModuleObjectLine +/* +class MyObjectLine { - /** - * @var int ID - */ + // @var int ID public $id; - /** - * @var mixed Sample line property 1 - */ + // @var mixed Sample line property 1 public $prop1; - /** - * @var mixed Sample line property 2 - */ + // @var mixed Sample line property 2 public $prop2; } +*/ \ No newline at end of file diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php index d7cb1559982..ead23c2891b 100644 --- a/htdocs/websites/class/website.class.php +++ b/htdocs/websites/class/website.class.php @@ -22,8 +22,7 @@ /** * \file websites/website.class.php * \ingroup websites - * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) - * Put some comments here + * \brief File for the CRUD class of website (Create/Read/Update/Delete) */ // Put here all includes required by your class file @@ -33,9 +32,6 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; /** * Class Website - * - * Put here description of your class - * @see CommonObject */ class Website extends CommonObject { @@ -137,16 +133,16 @@ class Website extends CommonObject $sql.= 'virtualhost,'; $sql.= 'fk_user_create,'; $sql.= 'date_creation,'; - $sql.= 'tmps'; + $sql.= 'tms'; $sql .= ') VALUES ('; $sql .= ' '.(! isset($this->entity)?'NULL':$this->entity).','; $sql .= ' '.(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").','; $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").','; $sql .= ' '.(! isset($this->status)?'NULL':$this->status).','; $sql .= ' '.(! isset($this->fk_default_home)?'NULL':$this->fk_default_home).','; - $sql .= ' '.(! isset($this->virtualhost)?'NULL':$this->virtualhost).','; + $sql .= ' '.(! isset($this->virtualhost)?'NULL':"'".$this->virtualhost)."',"; $sql .= ' '.(! isset($this->fk_user_create)?$user->id:$this->fk_user_create).','; - $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'"); + $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").","; $sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_creation)."'"); $sql .= ')'; @@ -237,7 +233,15 @@ class Website extends CommonObject } $this->db->free($resql); - if ($numrows) { + if ($numrows > 0) { + // Lines + $this->fetch_lines(); + { + return -3; + } + } + + if ($numrows > 0) { return 1; } else { return 0; @@ -250,6 +254,21 @@ class Website extends CommonObject } } + /** + * Load object lines in memory from the database + * + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetch_lines() + { + $this->lines=array(); + + // Load lines with object MyObjectLine + + return count($this->lines)?1:0; + } + + /** * Load object in memory from the database * @@ -463,32 +482,37 @@ class Website extends CommonObject /** * Load an object from its id and create a new one in database * - * @param int $fromid Id of object to clone - * - * @return int New id of clone + * @param User $user User making the clone + * @param int $fromid Id of object to clone + * @param string $newref New ref + * @return int New id of clone */ - public function createFromClone($fromid) + public function createFromClone($user, $fromid, $newref='') { - dol_syslog(__METHOD__, LOG_DEBUG); + global $hookmanager, $langs; + $error=0; - global $user; - $error = 0; - $object = new Website($this->db); + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); $this->db->begin(); // Load source object $object->fetch($fromid); - // Reset object - $object->id = 0; + // Reset some properties + unset($object->id); + unset($object->fk_user_creat); + unset($object->import_key); // Clear fields - // ... + $object->ref=$newref; + $object->fk_default_home=0; + $object->virtualhost=''; // Create clone + $object->context['createfromclone'] = 'createfromclone'; $result = $object->create($user); - - // Other options if ($result < 0) { $error ++; $this->errors = $object->errors; diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index 05f4abdbd79..5636f31d525 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -22,8 +22,7 @@ /** * \file websites/websitepage.class.php * \ingroup websites - * \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) - * Put some comments here + * \brief File for the CRUD class of websitepage (Create/Read/Update/Delete) */ // Put here all includes required by your class file @@ -518,6 +517,7 @@ class WebsitePage extends CommonObject /** * Load an object from its id and create a new one in database * + * @param User $user User making the clone * @param int $fromid Id of object to clone * @param string $newref New ref/alias of page * @param string $newlang New language @@ -525,13 +525,13 @@ class WebsitePage extends CommonObject * @param int $newwebsite 0=Same web site, 1=New web site * @return int New id of clone */ - public function createFromClone($fromid, $newref, $newlang='', $istranslation=0, $newwebsite=0) + public function createFromClone(User $user, $fromid, $newref, $newlang='', $istranslation=0, $newwebsite=0) { - global $user, $langs; + global $hookmanager, $langs; + $error = 0; dol_syslog(__METHOD__, LOG_DEBUG); - $error = 0; $object = new self($this->db); $this->db->begin(); @@ -551,9 +551,8 @@ class WebsitePage extends CommonObject if (! empty($newwebsite)) $object->fk_website=$newwebsite; // Create clone + $object->context['createfromclone'] = 'createfromclone'; $result = $object->create($user); - - // Other options if ($result < 0) { $error++; $this->error = $object->error; diff --git a/htdocs/websites/frametop.php b/htdocs/websites/frametop.php deleted file mode 100644 index 7cebf239e28..00000000000 --- a/htdocs/websites/frametop.php +++ /dev/null @@ -1,41 +0,0 @@ - - * Copyright (C) 2010 Laurent Destailleur - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/externalsite/frametop.php - * \ingroup externalsite - * \brief Top frame to show external web application - */ - -require ("../main.inc.php"); -//require_once (DOL_DOCUMENT_ROOT."/websites/class/website.class.php"); - -$langs->load("externalsite"); - -top_htmlhead("",""); - -print '' . "\n"; - -top_menu("","","_top"); - -print ''; - -/* -$website = new Website($db); -$listofwebsites = $website->fetchAll(); -*/ diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 3c64c0f287d..f9eb48518e8 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -555,11 +555,23 @@ if ($action == 'updatemeta') } // Update page -if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createpagefromclone') +if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createfromclone' || $action == 'confirm_createpagefromclone') || ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview')))) { $object->fetch(0, $website); + if ($action == 'confirm_createfromclone') + { + $objectnew = new Website($db); + $result = $objectnew->createFromClone($user, $object->id, GETPOST('siteref','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):'')); + if ($result < 0) + { + $error++; + setEventMessages($objectnew->error, $objectnew->errors, 'errors'); + $action='createfromclone'; + } + } + if ($action == 'confirm_createpagefromclone') { $istranslation=(GETPOST('is_a_translation','aZ09')=='on'?1:0); @@ -576,7 +588,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf if (! $error) { $objectpage = new WebsitePage($db); - $result = $objectpage->createFromClone($pageid, GETPOST('pageurl','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''), $istranslation, GETPOST('newwebsite','int')); + $result = $objectpage->createFromClone($user, $pageid, GETPOST('pageurl','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''), $istranslation, GETPOST('newwebsite','int')); if ($result < 0) { $error++; @@ -825,7 +837,7 @@ if (count($object->records) > 0) if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost; } - if ($website && $action == 'preview') + if ($website && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) { $disabled=''; if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"'; @@ -835,7 +847,7 @@ if (count($object->records) > 0) //print ''; print ''; print ''; - //print ''; + print ''; } print ''; @@ -843,7 +855,7 @@ if (count($object->records) > 0) // Button for websites print '
'; - if ($action == 'preview') + if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') { print '
'; print ''; @@ -933,14 +945,29 @@ if (count($object->records) > 0) print ''; - if ($action == 'preview' || $action == 'createpagefromclone') + if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') { $disabled=''; if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"'; + // Confirmation to clone + if ($action == 'createfromclone') { + // Create an array for form + $formquestion = array( + array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("Website") ,'value'=> 'copy_of_'.$objectpage->pageurl), + //array('type' => 'checkbox', 'name' => 'is_a_translation', 'label' => $langs->trans("SiteIsANewTranslation"), 'value' => 0), + //array('type' => 'other','name' => 'newlang','label' => $langs->trans("Language"), 'value' => $formadmin->select_language(GETPOST('newlang', 'az09')?GETPOST('newlang', 'az09'):$langs->defaultlang, 'newlang', 0, null, '', 0, 0, 'minwidth200')), + //array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("Website"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)) + ); + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?pageid=' . $pageid, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200); + + print $formconfirm; + } + if ($pageid > 0) { - // Confirmation to delete + // Confirmation to clone if ($action == 'createpagefromclone') { // Create an array for form $formquestion = array( @@ -971,7 +998,7 @@ if (count($object->records) > 0) print '
'; - if ($website && $pageid > 0 && ($action == 'preview' || $action == 'createpagefromclone')) + if ($website && $pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) { $websitepage = new WebSitePage($db); $websitepage->fetch($pageid); @@ -1017,7 +1044,7 @@ if (count($object->records) > 0) - if ($action == 'preview' || $action == 'createpagefromclone') + if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') { // Adding jquery code to change on the fly url of preview ext if (! empty($conf->use_javascript_ajax)) @@ -1181,14 +1208,42 @@ if ($action == 'editmeta' || $action == 'create') print '
'; - dol_fiche_head(); + $h = 0; + $head = array(); + + $head[$h][0] = dol_buildpath('/websites/index.php',1).'?id='.$object->id; + $head[$h][1] = $langs->trans("AddPage"); + $head[$h][2] = 'card'; + $h++; + + //dol_fiche_head($head, 'card', $langs->trans("AddPage"), -1, 'globe'); + if ($action == 'create') print_fiche_titre($langs->trans("AddPage")); print ''."\n"; + //print '
'; + + if ($action == 'create') + { + print ' * '.$langs->trans("CreateByFetchingExternalPage").'
'; + print ''; + print ''; + print '
'; + print $langs->trans("URL"); + print ''; + print ' '; + print ''; + print '
'; + + print '
'; + + print ' * '.$langs->trans("OrEnterPageInfoManually").'
'; + } + print ''; if ($action != 'create') { - print ''; print ''; print ''; print ''; print ''; print '
'; + print '
'; print $langs->trans('WEBSITE_PAGEURL'); print ''; print '/public/websites/index.php?website='.urlencode($website).'&pageid='.urlencode($pageid); @@ -1208,25 +1263,25 @@ if ($action == 'editmeta' || $action == 'create') print '
'; print $langs->trans('WEBSITE_PAGENAME'); print ''; - print ''; + print ''; print '
'; print $langs->trans('WEBSITE_TITLE'); print ''; - print ''; + print ''; print '
'; print $langs->trans('WEBSITE_DESCRIPTION'); print ''; - print ''; + print ''; print '
'; print $langs->trans('WEBSITE_KEYWORDS'); print ''; - print ''; + print ''; print '
'; @@ -1236,8 +1291,9 @@ if ($action == 'editmeta' || $action == 'create') print '
'; + //print '
'; - dol_fiche_end(); + //dol_fiche_end(); print '
'; @@ -1298,7 +1354,7 @@ print "
\n\n"; -if ($action == 'preview' || $action == 'createpagefromclone') +if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') { if ($pageid > 0) {