diff --git a/htdocs/admin/notification.php b/htdocs/admin/notification.php index 73fb3d91587..04427f636cd 100644 --- a/htdocs/admin/notification.php +++ b/htdocs/admin/notification.php @@ -55,7 +55,7 @@ if ($action == 'setvalue' && $user->admin) $result=dolibarr_set_const($db, "NOTIFICATION_EMAIL_FROM", $_POST["email_from"], 'chaine', 0, '', $conf->entity); if ($result < 0) $error++; - if (! $error) + if (! $error && is_array($_POST)) { //var_dump($_POST); foreach($_POST as $key => $val) @@ -172,7 +172,7 @@ $var=true; $i=0; foreach($listofnotifiedevents as $notifiedevent) { - + $label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']; if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder'); @@ -183,7 +183,7 @@ foreach($listofnotifiedevents as $notifiedevent) if ($i) print ', '; print $label; - + $i++; } print ''; @@ -213,7 +213,7 @@ $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents(); $var=true; foreach($listofnotifiedevents as $notifiedevent) { - + $label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']; if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder'); diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index 0336a2533c0..66776220d32 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2017 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 @@ -48,24 +48,21 @@ $acts[1] = "disable"; $actl[0] = img_picto($langs->trans("Disabled"),'switch_off'); $actl[1] = img_picto($langs->trans("Activated"),'switch_on'); -$listoffset=GETPOST('listoffset'); -$listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000; $status = 1; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if ($page == -1 || $page == null) { $page = 0 ; } -$offset = $listlimit * $page ; +// Load variable for pagination +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('admin')); -// This page is a generic page to edit dictionaries -// Put here declaration of dictionaries properties - // Name of SQL tables of dictionaries $tabname=array(); $tabname[1] = MAIN_DB_PREFIX."website"; @@ -118,7 +115,7 @@ $elementList = array(); $sourceList=array(); // Actions add or modify an entry into a dictionary -if (GETPOST('actionadd') || GETPOST('actionmodify')) +if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha')) { $listfield=explode(',',$tabfield[$id]); $listfieldinsert=explode(',',$tabfieldinsert[$id]); @@ -138,7 +135,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) } // Si verif ok et action add, on ajoute la ligne - if ($ok && GETPOST('actionadd')) + if ($ok && GETPOST('actionadd','alpha')) { if ($tabrowid[$id]) { @@ -200,7 +197,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) } // Si verif ok et action modify, on modifie la ligne - if ($ok && GETPOST('actionmodify')) + if ($ok && GETPOST('actionmodify','alpha')) { if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } @@ -252,7 +249,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition } -if (GETPOST('actioncancel')) +if (GETPOST('actioncancel','alpha')) { //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition } @@ -262,7 +259,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // delete if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } - $sql = "DELETE from ".MAIN_DB_PREFIX."website_pages WHERE fk_website ='".$rowid."'"; + $sql = "DELETE from ".MAIN_DB_PREFIX."website_page WHERE fk_website ='".$rowid."'"; $result = $db->query($sql); $sql = "DELETE from ".MAIN_DB_PREFIX."website WHERE rowid ='".$rowid."'"; @@ -341,7 +338,7 @@ if ($action == 'delete') //var_dump($elementList); /* - * Show a dictionary + * Show website list */ if ($id) { @@ -412,11 +409,11 @@ if ($id) $obj = new stdClass(); // If data was already input, we define them in obj to populate input fields. - if (GETPOST('actionadd')) + if (GETPOST('actionadd','alpha')) { foreach ($fieldlist as $key=>$val) { - if (GETPOST($val)) + if (GETPOST($val,'alpha')) $obj->$val=GETPOST($val); } } @@ -447,8 +444,7 @@ if ($id) - // List of available values in database - dol_syslog("htdocs/admin/dict", LOG_DEBUG); + // List of websites in database $resql=$db->query($sql); if ($resql) { @@ -465,14 +461,6 @@ if ($id) print ''; - // There is several pages - if ($num > $listlimit) - { - print ''; - } - // Title of lines print ''; foreach ($fieldlist as $field => $value) diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php index 8f8295f0e53..eca126697cc 100644 --- a/htdocs/bookmarks/bookmarks.lib.php +++ b/htdocs/bookmarks/bookmarks.lib.php @@ -53,11 +53,13 @@ function printBookmarksList($aDb, $aLangs) // No urlencode, all param $url will be urlencoded later if ($sortfield) $tmpurl.=($tmpurl?'&':'').'sortfield='.$sortfield; if ($sortorder) $tmpurl.=($tmpurl?'&':'').'sortorder='.$sortorder; - foreach($_POST as $key => $val) + if (is_array($_POST)) { - if (preg_match('/^search_/', $key) && $val != '') $tmpurl.=($tmpurl?'&':'').$key.'='.$val; + foreach($_POST as $key => $val) + { + if (preg_match('/^search_/', $key) && $val != '') $tmpurl.=($tmpurl?'&':'').$key.'='.$val; + } } - $url.=($tmpurl?'?'.$tmpurl:''); } diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index db3364ff04d..1b292b9e470 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -133,7 +133,7 @@ class Categorie extends CommonObject ); public $element='category'; - public $table_element='categories'; + public $table_element='categorie'; public $fk_parent; public $label; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 11aff01dc99..1c6186d5df4 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -35,14 +35,14 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $langs->load("categories"); $id=GETPOST('id','int'); -$ref=GETPOST('ref'); +$label=GETPOST('label'); $type=GETPOST('type'); $action=GETPOST('action','aZ09'); $confirm=GETPOST('confirm'); $removeelem = GETPOST('removeelem','int'); $elemid=GETPOST('elemid'); -if ($id == "") +if ($id == "" && $label == "") { dol_print_error('','Missing parameter id'); exit(); @@ -52,7 +52,7 @@ if ($id == "") $result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); -$result=$object->fetch($id); +$result=$object->fetch($id, $label); $object->fetch_optionals($id,$extralabels); if ($result <= 0) { @@ -195,7 +195,7 @@ $head = categories_prepare_head($object,$type); dol_fiche_head($head, 'card', $title, -1, 'category'); $linkback = ''.$langs->trans("BackToList").''; - +$object->next_prev_filter=" type = ".$object->type; $object->ref = $object->label; $morehtmlref='
'.$langs->trans("Root").' >> '; $ways = $object->print_all_ways(" >> ", '', 1); @@ -205,7 +205,7 @@ foreach ($ways as $way) } $morehtmlref.='
'; -dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); +dol_banner_tab($object, 'label', $linkback, ($user->societe_id?0:1), 'label', 'label', $morehtmlref, '', 0, '', '', 1); /* diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 76a53924ad5..9e293e09799 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -129,10 +129,13 @@ $hookmanager->initHooks(array('agenda')); if (GETPOST("viewlist") || $action == 'show_list') { $param=''; - foreach($_POST as $key => $val) + if (is_array($_POST)) { - if ($key=='token') continue; - $param.='&'.$key.'='.urlencode($val); + foreach($_POST as $key => $val) + { + if ($key=='token') continue; + $param.='&'.$key.'='.urlencode($val); + } } //print $param; header("Location: ".DOL_URL_ROOT.'/comm/action/listactions.php?'.$param); @@ -142,10 +145,13 @@ if (GETPOST("viewlist") || $action == 'show_list') if (GETPOST("viewperuser") || $action == 'show_peruser') { $param=''; - foreach($_POST as $key => $val) + if (is_array($_POST)) { - if ($key=='token') continue; - $param.='&'.$key.'='.urlencode($val); + foreach($_POST as $key => $val) + { + if ($key=='token') continue; + $param.='&'.$key.'='.urlencode($val); + } } //print $param; header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param); diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index 9cb14454cd5..9e0d1530e85 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -120,10 +120,13 @@ $hookmanager->initHooks(array('agendalist')); if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday")) { $param=''; - foreach($_POST as $key => $val) - { - $param.='&'.$key.'='.urlencode($val); - } + if (is_array($_POST)) + { + foreach($_POST as $key => $val) + { + $param.='&'.$key.'='.urlencode($val); + } + } //print $param; header("Location: ".DOL_URL_ROOT.'/comm/action/index.php?'.$param); exit; diff --git a/htdocs/core/actions_setmoduleoptions.inc.php b/htdocs/core/actions_setmoduleoptions.inc.php index 03b33b19eb1..b8ae96cb920 100644 --- a/htdocs/core/actions_setmoduleoptions.inc.php +++ b/htdocs/core/actions_setmoduleoptions.inc.php @@ -32,16 +32,19 @@ if ($action == 'setModuleOptions') $db->begin(); // Process common param fields - foreach($_POST as $key => $val) + if (is_array($_POST)) { - if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... + foreach($_POST as $key => $val) { - $param=GETPOST("param".$reg[1],'alpha'); - $value=GETPOST("value".$reg[1],'alpha'); - if ($param) + if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... { - $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; + $param=GETPOST("param".$reg[1],'alpha'); + $value=GETPOST("value".$reg[1],'alpha'); + if ($param) + { + $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } } } } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 96de26be956..7917234158e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -599,7 +599,7 @@ abstract class CommonObject } $datecreate = dol_now(); - + // Socpeople must have already been added by some a trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error $TListeContacts=$this->liste_contact(-1, $source); $already_added=false; @@ -611,11 +611,11 @@ abstract class CommonObject } } } - + if(!$already_added) { - + $this->db->begin(); - + // Insertion dans la base $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; @@ -623,7 +623,7 @@ abstract class CommonObject $sql.= "'".$this->db->idate($datecreate)."'"; $sql.= ", 4, ". $id_type_contact; $sql.= ")"; - + $resql=$this->db->query($sql); if ($resql) { @@ -636,7 +636,7 @@ abstract class CommonObject return -1; } } - + $this->db->commit(); return 1; } @@ -4726,6 +4726,9 @@ abstract class CommonObject return $buyPrice; } + + + /** * Function test if type is date * @@ -4734,7 +4737,7 @@ abstract class CommonObject */ protected function isDate($info) { - if(isset($info['type']) && $info['type']=='date') return true; + if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; else return false; } @@ -4880,40 +4883,6 @@ abstract class CommonObject return $query; } - /** - * Create object into database - * - * @param User $user User that creates - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, Id of created object if OK - */ - public function createCommon(User $user, $notrigger = false) - { - - $fields = array_merge(array('datec'=>$this->db->idate(dol_now())), $this->set_save_query()); - - foreach ($fields as $k => $v) { - - $keys[] = $k; - $values[] = $this->quote($v); - - } - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' - ( '.implode( ",", $keys ).' ) - VALUES ( '.implode( ",", $values ).' ) '; - $res = $this->db->query( $sql ); - if($res===false) { - - return false; - } - - // TODO Add triggers - - return true; - - } - /** * Function to load data into current object this * @@ -4921,39 +4890,39 @@ abstract class CommonObject */ private function set_vars_by_db(&$obj) { - foreach ($this->fields as $field => $info) - { - if($this->isDate($info)) - { - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; - else $this->{$field} = strtotime($obj->{$field}); - } - elseif($this->isArray($info)) - { - $this->{$field} = @unserialize($obj->{$field}); - // Hack for data not in UTF8 - if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); - } - elseif($this->isInt($info)) - { - $this->{$field} = (int) $obj->{$field}; - } - elseif($this->isFloat($info)) - { - $this->{$field} = (double) $obj->{$field}; - } - elseif($this->isNull($info)) - { - $val = $obj->{$field}; - // zero is not null - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); - } - else - { - $this->{$field} = $obj->{$field}; - } + foreach ($this->fields as $field => $info) + { + if($this->isDate($info)) + { + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; + else $this->{$field} = strtotime($obj->{$field}); + } + elseif($this->isArray($info)) + { + $this->{$field} = @unserialize($obj->{$field}); + // Hack for data not in UTF8 + if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); + } + elseif($this->isInt($info)) + { + $this->{$field} = (int) $obj->{$field}; + } + elseif($this->isFloat($info)) + { + $this->{$field} = (double) $obj->{$field}; + } + elseif($this->isNull($info)) + { + $val = $obj->{$field}; + // zero is not null + $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); + } + else + { + $this->{$field} = $obj->{$field}; + } - } + } } /** @@ -4963,21 +4932,134 @@ abstract class CommonObject */ private function get_field_list() { - $keys = array_keys($this->fields); - return implode(',', $keys); + $keys = array_keys($this->fields); + return implode(',', $keys); + } + + /** + * Add quote to field value if necessary + * + * @param string|int $value value to protect + * @return string|int + */ + protected function quote($value) { + + if(is_null($value)) return 'NULL'; + else if(is_numeric($value)) return $value; + else return "'".$this->db->escape( $value )."'"; + + } + + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, Id of created object if OK + */ + public function createCommon(User $user, $notrigger = false) + { + $error = 0; + + $fields = array_merge(array('datec'=>$this->db->idate(dol_now())), $this->set_save_query()); + + foreach ($fields as $k => $v) { + $keys[] = $k; + $values[] = $this->quote($v); + } + + $this->db->begin(); + + if (! $error) + { + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' + ( '.implode( ",", $keys ).' ) + VALUES ( '.implode( ",", $values ).' ) '; + $res = $this->db->query( $sql ); + if ($res===false) { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + + if (! $error && ! $notrigger) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); + + if (!$notrigger) { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class(self)).'_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return $this->id; + } + } + + /** + * 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; + + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); + + $this->db->begin(); + + // Load source object + $object->fetchCommon($fromid); + // Reset object + $object->id = 0; + + // Clear fields + // ... + + // Create clone + $result = $object->createCommon($user); + + // Other options + if ($result < 0) { + $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 * - * @param int $id Id object - * @param string $ref Ref - * - * @return int <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param string $ref Ref + * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetchCommon($id, $ref = null) { - if (empty($id) && empty($ref)) return false; $sql = 'SELECT '.$this->get_field_list().', datec, tms'; @@ -4991,13 +5073,20 @@ abstract class CommonObject { if ($obj = $this->db->fetch_object($res)) { - $this->id = $id; - $this->set_vars_by_db($obj); + if ($obj) + { + $this->id = $id; + $this->set_vars_by_db($obj); - $this->datec = $this->db->idate($obj->datec); - $this->tms = $this->db->idate($obj->tms); + $this->datec = $this->db->idate($obj->datec); + $this->tms = $this->db->idate($obj->tms); - return $this->id; + return $this->id; + } + else + { + return 0; + } } else { @@ -5019,15 +5108,15 @@ abstract class CommonObject * * @param User $user User that modifies * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK */ public function updateCommon(User $user, $notrigger = false) { + $error = 0; + $fields = $this->set_save_query(); foreach ($fields as $k => $v) { - if (is_array($key)){ $i=array_search($k, $key); if ( $i !== false) { @@ -5040,57 +5129,93 @@ abstract class CommonObject continue; } } - $tmp[] = $k.'='.$this->quote($v); } $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; - $res = $this->db->query( $sql ); - if($res===false) { - //error - return false; + $this->db->begin(); + + if (! $error) + { + $res = $this->db->query($sql); + if ($res===false) + { + $error++; + $this->errors[] = $this->db->lasterror(); + } } - // TODO Add triggers + if (! $error && ! $notrigger) { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class(self)).'_MODIFY',$user); + if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail + // End call triggers + } - return true; + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return $this->id; + } } /** * Delete object in database * - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int <0 if KO, >0 if OK + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, >0 if OK */ public function deleteCommon(User $user, $notrigger = false) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; + $error=0; - $res = $this->db->query( $sql ); - if($res===false) { - return false; + $this->db->begin(); + + if (! $error) { + if (! $notrigger) { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class(self)).'_DELETE', $user); + if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail + // End call triggers + } + } + + if (! $error) + { + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; + + $res = $this->db->query($sql); + if($res===false) { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return 1; } - - // TODO Add triggers - - return true; } /** - * Add quote to field value if necessary + * Initialise object with example values + * Id must be 0 if object instance is a specimen * - * @param string|int $value value to protect - * @return string|int + * @return void */ - protected function quote($value) { - - if(is_null($value)) return 'NULL'; - else if(is_numeric($value)) return $value; - else return "'".$this->db->escape( $value )."'"; + public function initAsSpecimenCommon() + { + $this->id = 0; + // TODO... } } - diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index a5ccb33f084..040ae1ba96e 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -314,7 +314,7 @@ class FormFile if (preg_match('/massfilesarea_/', $modulepart)) { - $out.='

'; + $out.='

'."\n"; $title=$langs->trans("MassFilesArea").' ('.$langs->trans("Hide").')'; $title.=''; +$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("MyObjects")); -$sql = "SELECT"; -$sql.= " t.rowid,"; -$sql.= " t.field1,"; -$sql.= " t.field2"; +// Build and execute select +// -------------------------------------------------------------------- +$sql = 'SELECT '; +foreach($object->fields as $key => $val) +{ + $sql.='t.'.$key.', '; +} // Add fields from extrafields -foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); +foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; -$sql.= " FROM ".MAIN_DB_PREFIX."mytable as t"; -if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."mytable_extrafields as ef on (t.rowid = ef.fk_object)"; -$sql.= " WHERE 1 = 1"; -//$sql.= " WHERE u.entity IN (".getEntity('mytable').")"; -if ($search_field1) $sql.= natural_search("field1",$search_field1); -if ($search_field2) $sql.= natural_search("field2",$search_field2); -if ($sall) $sql.= natural_search(array_keys($fieldstosearchall), $sall); +$sql=preg_replace('/, $/','', $sql); +$sql.= " FROM ".MAIN_DB_PREFIX."myobject as t"; +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."myobject_extrafields as ef on (t.rowid = ef.fk_object)"; +$sql.= " WHERE t.entity IN (".getEntity('myobject').")"; +foreach($search as $key => $val) +{ + if ($search[$key] != '') $sql.=natural_search($key, $search[$key], (($key == 'status')?2:($object->fields[$key]['type'] == 'integer'?1:0))); +} +if ($search_all) $sql.= natural_search(array_keys($fieldstosearchall), $search_all); // Add where from extra fields foreach ($search_array_options as $key => $val) { @@ -275,16 +260,37 @@ if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && exit; } + +// Output page +// -------------------------------------------------------------------- + llxHeader('', $title, $help_url); +// Example : Adding jquery code +print ''; + $arrayofselected=is_array($toselect)?$toselect:array(); $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; -if ($search_field1 != '') $param.= '&search_field1='.urlencode($search_field1); -if ($search_field2 != '') $param.= '&search_field2='.urlencode($search_field2); -if ($optioncss != '') $param.='&optioncss='.$optioncss; +foreach($search as $key => $val) +{ + $param.= '&search_'.$key.'='.urlencode($search[$key]); +} +if ($optioncss != '') $param.='&optioncss='.$optioncss; // Add $param from extra fields foreach ($search_array_options as $key => $val) { @@ -345,10 +351,16 @@ print '
'; - print_fleche_navigation($page, $_SERVER["PHP_SELF"], '', ($num > $listlimit), ''); - print '
'; -// LIST_OF_TD_TITLE_SEARCH -//if (! empty($arrayfields['t.field1']['checked'])) print ''; -//if (! empty($arrayfields['t.field2']['checked'])) print ''; +foreach($object->fields as $key => $val) +{ + if (in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) print ''; +} // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -376,25 +388,15 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (! empty($arrayfields['t.datec']['checked'])) +// Rest of fields search +foreach($object->fields as $key => $val) { - // Date creation - print ''; + if (! in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) print ''; } -if (! empty($arrayfields['t.tms']['checked'])) -{ - // Date modification - print ''; -} -/*if (! empty($arrayfields['u.statut']['checked'])) - { - // Status - print ''; - }*/ // Action column print ''; print ''."\n"; -// Fields title + +// Fields title label +// -------------------------------------------------------------------- print ''; -// LIST_OF_TD_TITLE_FIELDS -//if (! empty($arrayfields['t.field1']['checked'])) print_liste_field_titre($arrayfields['t.field1']['label'],$_SERVER['PHP_SELF'],'t.field1','',$param,'',$sortfield,$sortorder); -//if (! empty($arrayfields['t.field2']['checked'])) print_liste_field_titre($arrayfields['t.field2']['label'],$_SERVER['PHP_SELF'],'t.field2','',$param,'',$sortfield,$sortorder); +foreach($object->fields as $key => $val) +{ + if (in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; +} // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -417,7 +426,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab $align=$extrafields->getAlignFlag($key); $sortonfield = "ef.".$key; if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; - print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + print getTitleFieldOfList($langs->trans($extralabels[$key]), 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, ($align?'align="'.$align.'"':''), $sortfield, $sortorder)."\n"; } } } @@ -425,10 +434,16 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; -if (! empty($arrayfields['t.datec']['checked'])) print_liste_field_titre($arrayfields['t.datec']['label'],$_SERVER["PHP_SELF"],"t.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); -if (! empty($arrayfields['t.tms']['checked'])) print_liste_field_titre($arrayfields['t.tms']['label'],$_SERVER["PHP_SELF"],"t.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); -//if (! empty($arrayfields['t.status']['checked'])) print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"t.status","",$param,'align="center"',$sortfield,$sortorder); -print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); +// Rest of fields title +foreach($object->fields as $key => $val) +{ + if (! in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; +} +print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n"; print ''."\n"; @@ -440,6 +455,8 @@ foreach ($extrafields->attribute_computed as $key => $val) } +// Loop on record +// -------------------------------------------------------------------- $i=0; $totalarray=array(); while ($i < min($num, $limit)) @@ -449,18 +466,22 @@ while ($i < min($num, $limit)) { // Show here line of result print ''; - // LIST_OF_TD_FIELDS_LIST - /* - if (! empty($arrayfields['t.field1']['checked'])) + foreach($object->fields as $key => $val) { - print ''; - if (! $i) $totalarray['nbfield']++; + if (in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) + { + print ''; + if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); + elseif ($key == 'status') print ''; + else print $obj->$key; + print ''; + if (! $i) $totalarray['nbfield']++; + } } - if (! empty($arrayfields['t.field2']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - }*/ // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -483,30 +504,23 @@ while ($i < min($num, $limit)) $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - // Date creation - if (! empty($arrayfields['t.datec']['checked'])) + // Rest of fields + foreach($object->fields as $key => $val) { - print ''; - if (! $i) $totalarray['nbfield']++; + if (! in_array($key, array('datec','tms','status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; + if (! empty($arrayfields['t.'.$key]['checked'])) + { + print ''; + if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); + elseif ($key == 'status') print ''; + else print $obj->$key; + print ''; + if (! $i) $totalarray['nbfield']++; + } } - // Date modification - if (! empty($arrayfields['t.tms']['checked'])) - { - print ''; - if (! $i) $totalarray['nbfield']++; - } - // Status - /* - if (! empty($arrayfields['u.statut']['checked'])) - { - $userstatic->statut=$obj->statut; - print ''; - }*/ - // Action column print ''; else print ''; } - elseif ($totalarray['totalhtfield'] == $i) print ''; + elseif ($totalarray['totalhtfield'] == $i) print ''; elseif ($totalarray['totalvatfield'] == $i) print ''; elseif ($totalarray['totalttcfield'] == $i) print ''; else print ''; @@ -564,24 +578,28 @@ print ''."\n"; print ''."\n"; - -if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) +if ($nbtotalofrecords === '' || $nbtotalofrecords) { - // Show list of available documents - $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; - $urlsource.=str_replace('&','&',$param); + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) + { + require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'); + $formfile = new FormFile($db); - $filedir=$diroutputmassaction; - $genallowed=$user->rights->facture->lire; - $delallowed=$user->rights->facture->lire; + // Show list of available documents + $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource.=str_replace('&','&',$param); - print $formfile->showdocuments('massfilesarea_mymodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); + $filedir=$diroutputmassaction; + $genallowed=$user->rights->mymodule->read; + $delallowed=$user->rights->mymodule->read; + + print $formfile->showdocuments('massfilesarea_mymodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); + } + else + { + print '
'.$langs->trans("ShowTempMassFilesArea").''; + } } -else -{ - print '
'.$langs->trans("ShowTempMassFilesArea").''; -} - // End of page llxFooter(); diff --git a/htdocs/modulebuilder/template/sql/llx_myobject.key.sql b/htdocs/modulebuilder/template/sql/llx_myobject.key.sql index 812a98090af..4822d7c3ac4 100644 --- a/htdocs/modulebuilder/template/sql/llx_myobject.key.sql +++ b/htdocs/modulebuilder/template/sql/llx_myobject.key.sql @@ -14,6 +14,9 @@ -- along with this program. If not, see . -ALTER TABLE llx_myobject ADD UNIQUE INDEX uk_fk_othertable (fk_othertable); ---ALTER TABLE llx_myobject ADD CONSTRAINT llx_mytable_field_id FOREIGN KEY (fk_field) REFERENCES llx_myOthertable(rowid); +-- BEGIN MODULEBUILDER INDEXES +ALTER TABLE llx_myobject ADD UNIQUE INDEX idx_fieldobject (fieldobject); +-- END MODULEBUILDER INDEXES + +--ALTER TABLE llx_myobject ADD CONSTRAINT llx_myobject_field_id FOREIGN KEY (fk_field) REFERENCES llx_myotherobject(rowid); diff --git a/htdocs/modulebuilder/template/sql/llx_myobject.sql b/htdocs/modulebuilder/template/sql/llx_myobject.sql index 8cba239766f..b5810f0f227 100644 --- a/htdocs/modulebuilder/template/sql/llx_myobject.sql +++ b/htdocs/modulebuilder/template/sql/llx_myobject.sql @@ -13,9 +13,14 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . + CREATE TABLE llx_myobject( rowid INTEGER AUTO_INCREMENT PRIMARY KEY, + -- BEGIN MODULEBUILDER FIELDS entity INTEGER DEFAULT 1 NOT NULL, - fk_othertable INTEGER NOT NULL, - name VARCHAR(189) -); + label VARCHAR(255), + datec DATETIME NOT NULL, + tms TIMESTAMP NOT NULL, + status INTEGER + -- END MODULEBUILDER FIELDS +) ENGINE=innodb; \ No newline at end of file diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 3266d02f2f4..0a6c9052b91 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -561,7 +561,7 @@ if (empty($reshook)) { if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer)) { - $result = $object->delete(DolibarrApiAccess::$user); + $result = $object->delete($user); } if ($result > 0) diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index 9cda69560d5..908767afe32 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -200,22 +200,25 @@ if ($action == 'addtime' && $user->rights->projet->lire) { $timespent_duration=array(); - foreach($_POST as $key => $time) + if (is_array($_POST)) { - if (intval($time) > 0) + foreach($_POST as $key => $time) { - // Hours or minutes of duration - if (preg_match("/([0-9]+)duration(hour|min)/",$key,$matches)) + if (intval($time) > 0) { - $id = $matches[1]; - if ($id > 0) - { - // We store HOURS in seconds - if($matches[2]=='hour') $timespent_duration[$id] += $time*60*60; + // Hours or minutes of duration + if (preg_match("/([0-9]+)duration(hour|min)/",$key,$matches)) + { + $id = $matches[1]; + if ($id > 0) + { + // We store HOURS in seconds + if($matches[2]=='hour') $timespent_duration[$id] += $time*60*60; - // We store MINUTES in seconds - if($matches[2]=='min') $timespent_duration[$id] += $time*60; - } + // We store MINUTES in seconds + if($matches[2]=='min') $timespent_duration[$id] += $time*60; + } + } } } } diff --git a/htdocs/societe/price.php b/htdocs/societe/price.php index 5146e3ad6a5..d7b683f92e7 100644 --- a/htdocs/societe/price.php +++ b/htdocs/societe/price.php @@ -187,7 +187,7 @@ if (! empty($conf->notification->enabled)) $langs->load("mails"); $head = societe_prepare_head($object); -dol_fiche_head($head, 'price', $langs->trans("ThirdParty"), 0, 'company'); +dol_fiche_head($head, 'price', $langs->trans("ThirdParty"), -1, 'company'); $linkback = ''.$langs->trans("BackToList").''; @@ -200,11 +200,11 @@ print '
'; - print ''; - print ''; - print $form->selectarray('search_statut', array('-1'=>'','0'=>$langs->trans('Disabled'),'1'=>$langs->trans('Enabled')),$search_statut); - print ''; $searchpicto=$form->showFilterButtons(); @@ -402,11 +404,18 @@ print $searchpicto; print '
'.$obj->field1.''.$object->getLibStatut(3).''.$obj->field2.''; - print dol_print_date($db->jdate($obj->date_creation), 'dayhour'); - print ''.$object->getLibStatut(3).''; - print dol_print_date($db->jdate($obj->date_update), 'dayhour'); - print ''.$userstatic->getLibStatut(3).''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined @@ -536,7 +550,7 @@ if (isset($totalarray['totalhtfield'])) if ($num < $limit) print ''.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.price($totalarray['totalht']).''.price($totalarray['totalht']).''.price($totalarray['totalvat']).''.price($totalarray['totalttc']).'
'; if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { - print ''; + print ''; } if ($object->client) { - print ''; + print ''; + /*print '
' . $langs->trans('Prefix') . '' . $object->prefix_comm . '
' . $langs->trans('Prefix') . '' . $object->prefix_comm . '
'; + print '
'; print $langs->trans('CustomerCode') . ''; print $object->code_client; if ($object->check_codeclient() != 0) @@ -213,7 +213,7 @@ if ($object->client) { } if ($object->fournisseur) { - print '
'; + print '
'; print $langs->trans('SupplierCode') . ''; print $object->code_fournisseur; if ($object->check_codefournisseur() != 0) diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 0c8410213af..1d27e7c4986 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -2841,7 +2841,7 @@ class SupplierProposalLine extends CommonObjectLine $sql.= " ".price2num($this->localtax2_tx).","; $sql.= " '".$this->localtax1_type."',"; $sql.= " '".$this->localtax2_type."',"; - $sql.= " ".price2num($this->subprice).","; + $sql.= " ".(!empty($this->subprice)?price2num($this->subprice):"null").","; $sql.= " ".price2num($this->remise_percent).","; $sql.= " ".(isset($this->info_bits)?"'".$this->info_bits."'":"null").","; $sql.= " ".price2num($this->total_ht).","; diff --git a/htdocs/theme/eldy/ckeditor/config.js b/htdocs/theme/eldy/ckeditor/config.js index eabd0c58bd3..cddbef17dd1 100644 --- a/htdocs/theme/eldy/ckeditor/config.js +++ b/htdocs/theme/eldy/ckeditor/config.js @@ -15,6 +15,7 @@ CKEDITOR.editorConfig = function( config ) //config.height = '300px'; //config.resize_dir = 'vertical'; // horizontal, vertical, both config.removePlugins = 'elementspath,save'; // config.removePlugins = 'elementspath,save,font'; + //config.extraPlugins = 'docprops,scayt,showprotected'; config.removeDialogTabs = 'flash:advanced'; // config.removeDialogTabs = 'flash:advanced;image:Link'; config.protectedSource.push( /<\?[\s\S]*?\?>/g ); // Prevent PHP Code to be formatted //config.menu_groups = 'clipboard,table,anchor,link,image'; // for context menu 'clipboard,form,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,flash,checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea' @@ -25,7 +26,10 @@ CKEDITOR.editorConfig = function( config ) config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)'; //config.contentsCss = '/css/mysitestyles.css'; config.image_previewText=' '; // Must no be empty - + //config.autoParagraph = false; + //config.removeFormatTags = 'b,big,code,del,dfn,em,font,i,ins,kbd'; // See also rules on this.dataProcessor.writer.setRules + //config.forcePasteAsPlainText = true; + config.toolbar_Full = [ ['Templates','NewPage'], diff --git a/htdocs/theme/md/ckeditor/config.js b/htdocs/theme/md/ckeditor/config.js index 6f1bbe7fb30..e0374f6b271 100644 --- a/htdocs/theme/md/ckeditor/config.js +++ b/htdocs/theme/md/ckeditor/config.js @@ -15,6 +15,7 @@ CKEDITOR.editorConfig = function( config ) //config.height = '300px'; //config.resize_dir = 'vertical'; // horizontal, vertical, both config.removePlugins = 'elementspath,save'; // config.removePlugins = 'elementspath,save,font'; + //config.extraPlugins = 'docprops,scayt,showprotected'; config.removeDialogTabs = 'flash:advanced'; // config.removeDialogTabs = 'flash:advanced;image:Link'; config.protectedSource.push( /<\?[\s\S]*?\?>/g ); // Prevent PHP Code to be formatted //config.menu_groups = 'clipboard,table,anchor,link,image'; // for context menu 'clipboard,form,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,flash,checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea' @@ -25,7 +26,10 @@ CKEDITOR.editorConfig = function( config ) config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)'; //config.contentsCss = '/css/mysitestyles.css'; config.image_previewText=' '; // Must no be empty - + //config.autoParagraph = false; + //config.removeFormatTags = 'b,big,code,del,dfn,em,font,i,ins,kbd'; // See also rules on this.dataProcessor.writer.setRules + //config.forcePasteAsPlainText = true; + config.toolbar_Full = [ ['Templates','NewPage'], diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index 99fd4d64603..4f9dc58c615 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -129,7 +129,7 @@ class WebsitePage extends CommonObject $sql.= 'content,'; $sql.= 'status,'; $sql.= 'date_creation,'; - $sql.= 'date_modification'; + $sql.= 'tms'; $sql .= ') VALUES ('; $sql .= ' '.(! isset($this->fk_website)?'NULL':$this->fk_website).','; $sql .= ' '.(! isset($this->pageurl)?'NULL':"'".$this->db->escape($this->pageurl)."'").','; diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index a5c2ae4e046..2c9c364edac 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -129,6 +129,7 @@ if ($pageid > 0 && $action != 'add') global $dolibarr_main_data_root; $pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website; +$filehtmlheader=$pathofwebsite.'/header.html'; $filecss=$pathofwebsite.'/styles.css.php'; $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php'; $fileindex=$pathofwebsite.'/index.php'; @@ -240,25 +241,30 @@ if ($action == 'delete') // Update css if ($action == 'updatecss') { - //$db->begin(); - $res = $object->fetch(0, $website); - /* - $res = $object->update($user); - if ($res > 0) - { - $db->commit(); - $action=''; - } - else + // Html header file + $htmlheadercontent = ''."\n"; + $htmlheadercontent.= ''."\n"; + $htmlheadercontent.= ''."\n"; + $htmlheadercontent.= GETPOST('WEBSITE_HTML_HEADER'); + + dol_syslog("Save file css into ".$filehtmlheader); + + dol_mkdir($pathofwebsite); + $result = file_put_contents($filehtmlheader, $htmlheadercontent); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); + + if (! $result) { $error++; - $db->rollback(); - }*/ + setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors'); + } + // Css file $csscontent = ''."\n"; - $csscontent.= ''."\n"; + $csscontent.= ''."\n"; $csscontent.= '"."\n"; @@ -278,6 +284,7 @@ if ($action == 'updatecss') setEventMessages('Failed to write file '.$filecss, null, 'errors'); } + if (! $error) { setEventMessages($langs->trans("Saved"), null, 'mesgs'); @@ -310,7 +317,7 @@ if ($action == 'setashome') dol_delete_file($fileindex); $indexcontent = ''."\n"; $result = file_put_contents($fileindex, $indexcontent); @@ -406,6 +413,7 @@ if ($action == 'updatemeta') $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= '
'."\n"; + $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; @@ -414,8 +422,10 @@ if ($action == 'updatemeta') $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; - $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= 'ref.'/header.html"); ?>'."\n"; $tplcontent.= '
'."\n"; $tplcontent.= ''."\n"; @@ -458,7 +468,8 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage if (! is_link(dol_osencode($pathtomediasinwebsite))) { dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite); - symlink($pathtomedias, $pathtomediasinwebsite); + dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists + $result = symlink($pathtomedias, $pathtomediasinwebsite); } /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite')) @@ -560,6 +571,7 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage $tplcontent.= "// END PHP ?>\n"; $tplcontent.= ''."\n"; $tplcontent.= '
'."\n"; + $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; @@ -567,8 +579,10 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; $tplcontent.= ''."\n"; - $tplcontent.= ''."\n"; - $tplcontent.= ''.dol_escape_htmltag($objectpage->title).''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= ''."\n"; + $tplcontent.= 'ref.'/header.html"); ?>'."\n"; $tplcontent.= '
'."\n"; $tplcontent.= ''."\n"; @@ -939,6 +953,11 @@ if ($action == 'editcss') print '
'; + $htmlheader = @file_get_contents($filehtmlheader); + // Clean the php css file to remove php code and get only html part + $htmlheader = preg_replace('//s', '', $htmlheader); + + $csscontent = @file_get_contents($filecss); // Clean the php css file to remove php code and get only css part $csscontent = preg_replace('//s', '', $csscontent); @@ -957,11 +976,19 @@ if ($action == 'editcss') print '
'; print $langs->trans('WEBSITE_CSS_INLINE'); print ''; - print ''; print '
'; + print $langs->trans('WEBSITE_HTML_HEADER'); + print ''; + print ''; + print '
'; print $langs->trans('WEBSITE_CSS_URL'); print ''; @@ -1089,7 +1116,10 @@ if ($action == 'preview') $out.=$csscontent; $out.=''."\n"; - $out.=$objectpage->content."\n"; + // Replace php code + $content = preg_replace('/<\?php.*\?>/ims', '...php...', $objectpage->content); + + $out.=$content."\n"; $out.=''; diff --git a/test/phpunit/RestAPIDocumentTest.php b/test/phpunit/RestAPIDocumentTest.php index b60a7e9e833..7eb485ffbab 100644 --- a/test/phpunit/RestAPIDocumentTest.php +++ b/test/phpunit/RestAPIDocumentTest.php @@ -144,11 +144,11 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase echo __METHOD__.' Request POST url='.$url."\n"; - + // Send to non existant directory - + dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit'); - + //$data = '{ "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "" }'; $data = array( 'filename'=>"mynewfile.txt", @@ -158,7 +158,7 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase 'filecontent'=>"content text", 'fileencoding'=>"" ); - + $result = getURLContent($url, 'POST', $data, 1); echo __METHOD__.' Result for sending document: '.var_export($result, true)."\n"; echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n"; @@ -166,11 +166,11 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase $this->assertNotNull($object, 'Parsing of json result must no be null'); $this->assertEquals('401', $object['error']['code']); - + // Send to existant directory - + dol_mkdir(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit2'); - + $data = array( 'filename'=>"mynewfile.txt", 'modulepart'=>"medias", @@ -187,5 +187,7 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase $this->assertNotNull($object2, 'Parsing of json result must no be null'); $this->assertEquals($result2['curl_error_no'], ''); $this->assertEquals($result2['content'], 'true'); + + dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit'); } }