From 640bf7c34b2d49c2d2815a1370f7938bab381d94 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 23 Sep 2014 12:18:42 +0200 Subject: [PATCH 01/10] Uniformize field name --- htdocs/comm/action/card.php | 14 +++--- htdocs/comm/action/class/actioncomm.class.php | 49 +++++++++++++------ htdocs/comm/action/peruser.php | 2 +- .../install/mysql/migration/3.6.0-3.7.0.sql | 6 ++- .../mysql/tables/llx_actioncomm_resources.sql | 10 ++-- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 0e6a6c6fd10..237c55e7678 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -105,11 +105,11 @@ if (! empty($_POST['removedassigned'])) if (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser')) { // Add a new user - if (GETPOST('affectedto') > 0) + if (GETPOST('assignedtouser') > 0) { $assignedtouser=array(); if (! empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); - $assignedtouser[GETPOST('affectedto')]=array('transparency'=>GETPOST('transparency'),'mandatory'=>1); + $assignedtouser[GETPOST('assignedtouser')]=array('transparency'=>GETPOST('transparency'),'mandatory'=>1); $_SESSION['assignedtouser']=dol_json_encode($assignedtouser); } $donotclearsession=1; @@ -647,11 +647,11 @@ if ($action == 'create') print ''.$langs->trans("ActionAffectedTo").''; if (empty($donotclearsession)) { - $assignedtouser=GETPOST("affectedtouser")?GETPOST("affectedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id); + $assignedtouser=GETPOST("assignedtouser")?GETPOST("assignedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id); $_SESSION['assignedtouser']=dol_json_encode(array($assignedtouser=>array('transparency'=>1,'mandatory'=>1))); } - print $form->select_dolusers_forevent(($action=='create'?'add':'update'),'affectedto',1); - //print $form->select_dolusers(GETPOST("affectedto")?GETPOST("affectedto"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id),'affectedto',1); + print $form->select_dolusers_forevent(($action=='create'?'add':'update'),'assignedtouser',1); + //print $form->select_dolusers(GETPOST("assignedtouser")?GETPOST("assignedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id),'affectedto',1); print ''; print ''; @@ -904,8 +904,8 @@ if ($id > 0) if (is_object($object->usertodo)) $listofuserid[$object->usertodo->id]=array('id'=>$object->usertodo->id,'transparency'=>$object->transparency); $_SESSION['assignedtouser']=dol_json_encode($listofuserid); } - print $form->select_dolusers_forevent(($action=='create'?'add':'update'),'affectedto',1); - //print $form->select_dolusers($object->usertodo->id>0?$object->usertodo->id:-1,'affectedto',1); + print $form->select_dolusers_forevent(($action=='create'?'add':'update'),'assignedtouser',1); + //print $form->select_dolusers($object->usertodo->id>0?$object->usertodo->id:-1,'assignedtouser',1); print ''; print '

'; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 731d82dba2f..f1acf8c29b4 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -211,22 +211,43 @@ class ActionComm extends CommonObject { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm","id"); - // Actions on extra fields (by external module or standard code) - $hookmanager->initHooks(array('actioncommdao')); - $parameters=array('actcomm'=>$this->id); - $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) + // Now insert assignedusers + if (! $error) + { + foreach($this->userassigned as $key => $val) + { + $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; + $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", 0, ".$val['transparency'].", 0)"; + + $resql = $this->db->query($sql); + if (! $resql) + { + $error++; + $this->errors[]=$this->db->lasterror(); + } + //var_dump($sql);exit; + } + } + + if (! $error) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result=$this->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } + // Actions on extra fields (by external module or standard code) + $hookmanager->initHooks(array('actioncommdao')); + $parameters=array('actcomm'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + else if ($reshook < 0) $error++; } - else if ($reshook < 0) $error++; if (! $error && ! $notrigger) { diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index abd8b71a699..22f968e2b4a 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -656,7 +656,7 @@ jQuery(document).ready(function() { if (ids == \'none\') /* No event */ { /* alert(\'no event\'); */ - url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=create&affectedto="+userid+"&datep="+year+month+day+hour+min+"00&backtopage='.urlencode($_SERVER["PHP_SELF"].'?year='.$year.'&month='.$month.'&day='.$day).'" + url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=create&assignedtouser="+userid+"&datep="+year+month+day+hour+min+"00&backtopage='.urlencode($_SERVER["PHP_SELF"].'?year='.$year.'&month='.$month.'&day='.$day).'" window.location.href = url; } else if (ids.indexOf(",") > -1) /* There is several events */ diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index dab26d32934..0ae4ee8bd22 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -131,6 +131,8 @@ ALTER TABLE llx_user ADD COLUMN weeklyhours double(16,8); ALTER TABLE llx_projet_task_time ADD COLUMN task_datehour datetime after task_date; +ALTER TABLE llx_actioncomm_resources CHANGE COLUMN transparent transparency smallint default 1; + -- Localtaxes by thirds ALTER TABLE llx_c_tva MODIFY COLUMN localtax1 varchar(10); @@ -1071,11 +1073,11 @@ CREATE TABLE llx_fichinterdet_extrafields ALTER TABLE llx_fichinterdet_extrafields ADD INDEX idx_ficheinterdet_extrafields (fk_object); -CREATE TABLE IF NOT EXISTS llx_usergroup_extrafields ( +CREATE TABLE llx_usergroup_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, fk_object integer NOT NULL, import_key varchar(14) -- import key -) ENGINE=InnoDB ; +) ENGINE=innodb; ALTER TABLE llx_usergroup_extrafields ADD INDEX idx_usergroup_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_actioncomm_resources.sql b/htdocs/install/mysql/tables/llx_actioncomm_resources.sql index bd48ad4f66d..484cd39fb82 100644 --- a/htdocs/install/mysql/tables/llx_actioncomm_resources.sql +++ b/htdocs/install/mysql/tables/llx_actioncomm_resources.sql @@ -23,10 +23,10 @@ create table llx_actioncomm_resources ( rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_actioncomm integer NOT NULL, - element_type varchar(50) NOT NULL, - fk_element integer NOT NULL, + fk_actioncomm integer NOT NULL, -- Id into llx_actioncomm + element_type varchar(50) NOT NULL, -- Type of resource ('user', 'resource') + fk_element integer NOT NULL, -- Id into table llx_user or llx_resource answer_status varchar(50) NULL, - mandatory smallint, - transparent smallint + mandatory smallint, + transparency smallint default 1 -- Used to say if event is 1=OPAQUE=busy or 0=TRANSPARENT ) ENGINE=innodb; From 7224f642240638205a99333d0066b45981e3da86 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 23 Sep 2014 16:15:15 +0200 Subject: [PATCH 02/10] Work on multi user for events. Fix: Modules must be reloaded after migration. --- htdocs/comm/action/card.php | 92 +++++++++++++------ htdocs/comm/action/class/actioncomm.class.php | 55 ++++++++++- htdocs/core/class/html.form.class.php | 33 +++++-- htdocs/core/lib/json.lib.php | 2 +- htdocs/install/upgrade2.php | 4 +- 5 files changed, 141 insertions(+), 45 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 237c55e7678..7ca82a2751e 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -93,7 +93,10 @@ if (! empty($_POST['removedassigned'])) $idtoremove=$_POST['removedassigned']; if (! empty($_SESSION['assignedtouser'])) $tmpassigneduserids=dol_json_decode($_SESSION['assignedtouser'],1); else $tmpassigneduserids=array(); - unset($tmpassigneduserids[$idtoremove]); + foreach ($tmpassigneduserids as $key => $val) + { + if ($val['id'] == $idtoremove) unset($tmpassigneduserids[$key]); + } //var_dump($_POST['removedassigned']);exit; $_SESSION['assignedtouser']=dol_json_encode($tmpassigneduserids); $donotclearsession=1; @@ -108,8 +111,11 @@ if (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser')) if (GETPOST('assignedtouser') > 0) { $assignedtouser=array(); - if (! empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); - $assignedtouser[GETPOST('assignedtouser')]=array('transparency'=>GETPOST('transparency'),'mandatory'=>1); + if (! empty($_SESSION['assignedtouser'])) + { + $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); + } + $assignedtouser[GETPOST('assignedtouser')]=array('id'=>GETPOST('assignedtouser'), 'transparency'=>GETPOST('transparency'),'mandatory'=>1); $_SESSION['assignedtouser']=dol_json_encode($assignedtouser); } $donotclearsession=1; @@ -202,22 +208,23 @@ if ($action == 'add') $object->percentage = $percentage; $object->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * 60; - $listofuserid=dol_json_decode($_SESSION['assignedtouser']); + $listofuserid=array(); + if (! empty($_SESSION['assignedtouser'])) $listofuserid=dol_json_decode($_SESSION['assignedtouser']); $i=0; foreach($listofuserid as $key => $value) { if ($i == 0) // First entry { $usertodo=new User($db); - if ($key > 0) + if ($value['id'] > 0) { - $usertodo->fetch($key); + $usertodo->fetch($value['id']); } $object->usertodo = $usertodo; $object->transparency = (GETPOST("transparency")=='on'?1:0); } - $object->userassigned[$key]=array('id'=>$key, 'transparency'=>(GETPOST("transparency")=='on'?1:0)); + $object->userassigned[$value['id']]=array('id'=>$value['id'], 'transparency'=>(GETPOST("transparency")=='on'?1:0)); $i++; } @@ -281,6 +288,8 @@ if ($action == 'add') { if (! $object->error) { + unset($_SESSION['assignedtouser']); + $db->commit(); if (! empty($backtopage)) { @@ -337,6 +346,7 @@ if ($action == 'update') if ($p2min == -1) $p2min='0'; $object->fetch($id); + $object->fetch_userassigned(); $datep=dol_mktime($fulldayevent?'00':$aphour, $fulldayevent?'00':$apmin, 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datef=dol_mktime($fulldayevent?'23':$p2hour, $fulldayevent?'59':$p2min, $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); @@ -363,26 +373,26 @@ if ($action == 'update') setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")),$object->errors,'errors'); $action = 'edit'; } - // Users - $listofuserid=dol_json_decode($_SESSION['assignedtouser']); - $i=0; - foreach($listofuserid as $key => $value) + $listofuserid=array(); + //$assignedtouser=(GETPOST("assignedtouser") >0)?GETPOST("assignedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : 0); + $assignedtouser=(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : 0); + if ($assignedtouser) $listofuserid[$assignedtouser]=array('id'=>$assignedtouser, 'mandatory'=>0, 'transparency'=>$object->transparency); // Owner first + + if (! empty($_SESSION['assignedtouser'])) { - if ($i == 0) // First entry + // Restore array with key with same value than param 'id' + $tmplist1=dol_json_decode($_SESSION['assignedtouser'], true); $tmplist2=array(); + foreach($tmplist1 as $key => $val) { - $usertodo=new User($db); - if ($key > 0) - { - $usertodo->fetch($key); - } - $object->usertodo = $usertodo; - $object->transparency=(GETPOST("transparency")=='on'?1:0); + if ($val['id'] && $val['id'] != $assignedtouser) $listofuserid[$val['id']]=$val; } + } - $object->userassigned[$key]=array('id'=>$key, 'transparency'=>(GETPOST("transparency")=='on'?1:0)); - - $i++; + $object->userassigned=array(); // Clear old content + foreach($listofuserid as $key => $val) + { + $object->userassigned[$val['id']]=array('id'=>$val['id'], 'mandatory'=>0, 'transparency'=>(GETPOST("transparency")=='on'?1:0)); } if (! empty($conf->global->AGENDA_ENABLE_DONEBY)) @@ -424,6 +434,8 @@ if ($action == 'update') if ($result > 0) { + unset($_SESSION['assignedtouser']); + $db->commit(); } else @@ -438,6 +450,7 @@ if ($action == 'update') { if (! empty($backtopage)) { + unset($_SESSION['assignedtouser']); header("Location: ".$backtopage); exit; } @@ -474,6 +487,8 @@ if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') if ($action == 'mupdate') { $object->fetch($id); + $object->fetch_userassigned(); + $shour = dol_print_date($object->datep,"%H"); $smin = dol_print_date($object->datep, "%M"); @@ -645,11 +660,19 @@ if ($action == 'create') // Assigned to print ''; @@ -771,10 +794,11 @@ if ($action == 'create') // View or edit if ($id > 0) { - $result=$object->fetch($id); - $object->fetch_optionals($id,$extralabels); + $result1=$object->fetch($id); + $result2=$object->fetch_userassigned(); + $result3=$object->fetch_optionals($id,$extralabels); - if ($result < 0) + if ($result1 < 0 || $result2 < 0 || $result3 < 0) { dol_print_error($db,$object->error); exit; @@ -901,7 +925,8 @@ if ($id > 0) $listofuserid=array(); if (empty($donotclearsession)) { - if (is_object($object->usertodo)) $listofuserid[$object->usertodo->id]=array('id'=>$object->usertodo->id,'transparency'=>$object->transparency); + if (is_object($object->usertodo)) $listofuserid[$object->usertodo->id]=array('id'=>$object->usertodo->id,'transparency'=>$object->transparency); // Owner first + $listofuserid=array_merge($listofuserid,$object->userassigned); $_SESSION['assignedtouser']=dol_json_encode($listofuserid); } print $form->select_dolusers_forevent(($action=='create'?'add':'update'),'assignedtouser',1); @@ -1094,8 +1119,17 @@ if ($id > 0) } // Assigned to - print ''; print '
'.$langs->trans("ActionAffectedTo").''; + $listofuserid=array(); if (empty($donotclearsession)) { $assignedtouser=GETPOST("assignedtouser")?GETPOST("assignedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id); - $_SESSION['assignedtouser']=dol_json_encode(array($assignedtouser=>array('transparency'=>1,'mandatory'=>1))); + if ($assignedtouser) $listofuserid[$assignedtouser]=array('id'=>$assignedtouser,'mandatory'=>0,'transparency'=>$object->transparency); // Owner first + $_SESSION['assignedtouser']=dol_json_encode($listofuserid); } + /* + if (empty($donotclearsession)) + { + $assignedtouser=GETPOST("assignedtouser")?GETPOST("assignedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id); + $_SESSION['assignedtouser']=dol_json_encode(array($assignedtouser=>array('id'=>$assignedtouser,'transparency'=>1,'mandatory'=>1))); + }*/ print $form->select_dolusers_forevent(($action=='create'?'add':'update'),'assignedtouser',1); //print $form->select_dolusers(GETPOST("assignedtouser")?GETPOST("assignedtouser"):(! empty($object->usertodo->id) && $object->usertodo->id > 0 ? $object->usertodo->id : $user->id),'affectedto',1); print '
'.$langs->trans("ActionAffectedTo").''; - if ($object->usertodo->id > 0) print $object->usertodo->getNomUrl(1); + //if ($object->usertodo->id > 0) print $object->usertodo->getNomUrl(1); + print '
'.$langs->trans("ActionAffectedTo").''; + $listofuserid=array(); + if (empty($donotclearsession)) + { + if (is_object($object->usertodo)) $listofuserid[$object->usertodo->id]=array('id'=>$object->usertodo->id,'transparency'=>$object->transparency); // Owner first + $listofuserid=array_merge($listofuserid,$object->userassigned); + $_SESSION['assignedtouser']=dol_json_encode($listofuserid); + //var_dump($_SESSION['assignedtouser']); + } + print $form->select_dolusers_forevent('view','assignedtouser',1); print '


'; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index f1acf8c29b4..b12dc5fb702 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -62,7 +62,7 @@ class ActionComm extends CommonObject var $priority; // Small int (0 By default) var $note; // Description - var $userassigned; // Array of user ids + var $userassigned = array(); // Array of user ids var $usertodo; // Object user of owner var $userdone; // Object user that did action (deprecated) @@ -217,7 +217,7 @@ class ActionComm extends CommonObject foreach($this->userassigned as $key => $val) { $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; - $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", 0, ".$val['transparency'].", 0)"; + $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".($val['mandatory']?$val['mandatory']:'0').", ".($val['transparency']?$val['transparency']:'0').", ".($val['answer_status']?$val['answer_status']:'0').")"; $resql = $this->db->query($sql); if (! $resql) @@ -375,6 +375,34 @@ class ActionComm extends CommonObject } } + + /** + * Initialize this->userassigned array + * + * @return int <0 if KO, >0 if OK + */ + function fetch_userassigned() + { + global $langs; + $sql.="SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency"; + $sql.=" FROM ".MAIN_DB_PREFIX."actioncomm_resources"; + $sql.=" WHERE element_type = 'user' AND fk_actioncomm = ".$this->id; + $resql2=$this->db->query($sql); + if ($resql2) + { + while ($obj = $this->db->fetch_object($resql2)) + { + $this->userassigned[$obj->fk_element]=array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency); + } + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + /** * Delete event from database * @@ -519,7 +547,28 @@ class ActionComm extends CommonObject } else if ($reshook < 0) $error++; - if (! $notrigger) + // Now insert assignedusers + if (! $error) + { + $sql ="DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".$this->id." AND element_type = 'user'"; + $resql = $this->db->query($sql); + + foreach($this->userassigned as $key => $val) + { + $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; + $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".($val['manadatory']?$val['manadatory']:'0').", ".($val['transparency']?$val['transparency']:'0').", ".($val['answer_status']?$val['answer_status']:'0').")"; + + $resql = $this->db->query($sql); + if (! $resql) + { + $error++; + $this->errors[]=$this->db->lasterror(); + } + //var_dump($sql);exit; + } + } + + if (! $error && ! $notrigger) { // Call trigger $result=$this->call_trigger('ACTION_MODIFY',$user); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 357270efb2d..08f384612f7 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1275,6 +1275,7 @@ class Form /** * Return select list of users. Selected users are stored into session. + * List of users are provided into $_SESSION['assignedtouser']. * * @param string $action Value for $action * @param string $htmlname Field name in form @@ -1295,23 +1296,35 @@ class Form global $conf,$user,$langs; $userstatic=new User($this->db); + $out=''; // Method with no ajax //$out.=''; - $out.=''; - $out.=''; - $out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter); - $out.=''; + if ($action == 'view') + { + $out.=''; + } + else + { + $out.=''; + $out.=''; + $out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter); + $out.=''; + } $assignedtouser=array(); - if (!empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); - if (count($assignedtouser)) $out.='
'; - $i=0; + if (!empty($_SESSION['assignedtouser'])) + { + $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); + } + if (count($assignedtouser) && $action != 'view') $out.='
'; + $i=0; $ownerid=0; foreach($assignedtouser as $key => $value) { - $userstatic->fetch($key); + if ($value['id'] == $ownerid) continue; + $userstatic->fetch($value['id']); $out.=$userstatic->getNomUrl(1); - if ($i == 0) $out.=' ('.$langs->trans("Owner").')'; - $out.=' '; + if ($i == 0) { $ownerid = $value['id']; $out.=' ('.$langs->trans("Owner").')'; } + if ($i > 0 && $action != 'view') $out.=' '; //$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional")); //$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy")); $out.='
'; diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 69dbb4eba1a..ba7f4cd3f90 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -254,7 +254,7 @@ function dol_json_decode($json, $assoc=false) foreach ($array as $key => $value) { - $object->{$key} = $value; + if ($key) $object->{$key} = $value; } return $object; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index f9fa76541a5..0bf76c7d729 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -343,8 +343,8 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) // No specific scripts // Tasks to do always and only into last targeted version - $afterversionarray=explode('.','3.4.9'); // target is after this - $beforeversionarray=explode('.','3.5.9'); // target is before this + $afterversionarray=explode('.','3.6.9'); // target is after this + $beforeversionarray=explode('.','3.7.9'); // target is before this if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) { // Reload modules (this must be always and only into last targeted version) From 691658cde37c9bc371a707ca23062786eb71651e Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Tue, 23 Sep 2014 16:52:15 +0200 Subject: [PATCH 03/10] add the clone action for a social contribution - With option to clone it to the next month by default --- htdocs/compta/sociales/charges.php | 81 ++++++++++++++++++- .../sociales/class/chargesociales.class.php | 28 +++++-- htdocs/langs/en_US/compta.lang | 3 + 3 files changed, 105 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 059a3ccf544..0ccd450e0cb 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -149,6 +149,68 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr } } + // Action clone object +if ($action == 'confirm_clone' && $confirm != 'yes') { $action=''; } +if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) +{ + + $db->begin(); + + $originalId = $id; + + $object = new ChargeSociales($db); + $object->fetch($id); + + if ($object->id > 0) + { + $object->paye = 0; + $object->id = $object->ref = null; + + if(GETPOST('clone_for_next_month') != '') { + + $object->date_ech = strtotime('+1month', $object->date_ech); + $object->periode = strtotime('+1month', $object->periode); + } + + if ($object->check()) + { + $id = $object->create($user); + if ($id > 0) + { + $db->commit(); + $db->close(); + + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $id=$originalId; + $db->rollback(); + + if (count($object->errors)) + { + setEventMessage($object->errors, 'errors'); + dol_print_error($db,$object->errors); + } + else + { + setEventMessage($langs->trans($object->error), 'errors'); + dol_print_error($db,$object->error); + } + } + } + } + else + { + $db->rollback(); + dol_print_error($db,$object->error); + } + +} + + + /* @@ -239,7 +301,18 @@ if ($id > 0) $head=tax_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("SocialContribution"),0,'bill'); - + + // Clone confirmation + if ($action === 'clone') + { + $formclone=array( + array('type' => 'checkbox', 'name' => 'clone_for_next_month','label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1), + + ); + + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneTax'),$langs->trans('ConfirmCloneTax',$object->ref),'confirm_clone',$formclone,'yes'); + } + // Confirmation de la suppression de la charge if ($action == 'paid') { @@ -419,6 +492,12 @@ if ($id > 0) { print "id&action=paid\">".$langs->trans("ClassifyPaid").""; } + + // Clone + if ($user->rights->tax->charges->creer) + { + print "id&action=clone\">".$langs->trans("ToClone").""; + } // Delete if ($user->rights->tax->charges->supprimer) diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 09e4ebaef0c..807466ef95f 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -106,7 +106,24 @@ class ChargeSociales extends CommonObject return -1; } } + /* + * Check if a social contribution can be created into database + * + */ + function check() { + + $newamount=price2num($this->amount,'MT'); + // Validation parametres + if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode)) + { + + return false; + } + + + return true; + } /** * Create a social contribution into database @@ -121,12 +138,11 @@ class ChargeSociales extends CommonObject // Nettoyage parametres $newamount=price2num($this->amount,'MT'); - // Validation parametres - if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode)) - { - $this->error="ErrorBadParameter"; - return -2; - } + if(!$this->check()) { + $this->error="ErrorBadParameter"; + return -2; + } + $this->db->begin(); diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index 5ec9bd62a54..47e19c78d21 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -204,3 +204,6 @@ ACCOUNTING_VAT_ACCOUNT=Default accountancy code for collecting VAT ACCOUNTING_VAT_BUY_ACCOUNT=Default accountancy code for paying VAT ACCOUNTING_ACCOUNT_CUSTOMER=Accountancy code by default for customer thirdparties ACCOUNTING_ACCOUNT_SUPPLIER=Accountancy code by default for supplier thirdparties +CloneTax=Clone a social contribution +ConfirmCloneTax=Confirm the clone of a social contribution +CloneTaxForNextMonth=Clone it for next month \ No newline at end of file From dd864530201d3eb3c2ae9e5dfe3da26276898c8d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 23 Sep 2014 17:54:03 +0200 Subject: [PATCH 04/10] Add field color into table of type of events --- htdocs/admin/dict.php | 8 ++++---- htdocs/comm/action/class/actioncomm.class.php | 3 ++- htdocs/comm/action/peruser.php | 16 +++++++++++++++- htdocs/core/class/html.form.class.php | 6 ++++-- htdocs/install/mysql/migration/3.6.0-3.7.0.sql | 2 ++ htdocs/install/mysql/tables/llx_c_actioncomm.sql | 3 ++- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index d9ebddf2b22..dd8fa456600 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -133,7 +133,7 @@ $tabsql[2] = "SELECT d.rowid as rowid, d.code_departement as code, d.nom as libe $tabsql[3] = "SELECT r.rowid as rowid, r.code_region as code, r.nom as libelle, r.fk_pays as country_id, c.code as country_code, c.label as country, r.active FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE r.fk_pays=c.rowid and c.active=1"; $tabsql[4] = "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_country"; $tabsql[5] = "SELECT c.rowid as rowid, c.code as code, c.label, c.active FROM ".MAIN_DB_PREFIX."c_civility AS c"; -$tabsql[6] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.type, a.active, a.module, a.position FROM ".MAIN_DB_PREFIX."c_actioncomm AS a"; +$tabsql[6] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.type, a.active, a.module, a.color, a.position FROM ".MAIN_DB_PREFIX."c_actioncomm AS a"; $tabsql[7] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, a.deductible, c.code as country_code, c.label as country, a.fk_pays as country_id, a.active FROM ".MAIN_DB_PREFIX."c_chargesociales AS a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_pays=c.rowid and c.active=1"; $tabsql[8] = "SELECT t.id as rowid, t.code as code, t.libelle, t.fk_country as country_id, c.code as country_code, c.label as country, t.active FROM ".MAIN_DB_PREFIX."c_typent as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON t.fk_country=c.rowid"; $tabsql[9] = "SELECT code_iso as code, label, unicode, active FROM ".MAIN_DB_PREFIX."c_currencies"; @@ -187,7 +187,7 @@ $tabfield[2] = "code,libelle,region_id,region,country"; // "code,libelle,regio $tabfield[3] = "code,libelle,country_id,country"; $tabfield[4] = "code,label"; $tabfield[5] = "code,label"; -$tabfield[6] = "code,libelle,type,position"; +$tabfield[6] = "code,libelle,type,color,position"; $tabfield[7] = "code,libelle,country_id,country,accountancy_code,deductible"; $tabfield[8] = "code,libelle,country_id,country"; $tabfield[9] = "code,label,unicode"; @@ -214,7 +214,7 @@ $tabfieldvalue[2] = "code,libelle,region"; // "code,libelle,region" $tabfieldvalue[3] = "code,libelle,country"; $tabfieldvalue[4] = "code,label"; $tabfieldvalue[5] = "code,label"; -$tabfieldvalue[6] = "code,libelle,type,position"; +$tabfieldvalue[6] = "code,libelle,type,color,position"; $tabfieldvalue[7] = "code,libelle,country,accountancy_code,deductible"; $tabfieldvalue[8] = "code,libelle,country"; $tabfieldvalue[9] = "code,label,unicode"; @@ -241,7 +241,7 @@ $tabfieldinsert[2] = "code_departement,nom,fk_region"; $tabfieldinsert[3] = "code_region,nom,fk_pays"; $tabfieldinsert[4] = "code,label"; $tabfieldinsert[5] = "code,label"; -$tabfieldinsert[6] = "code,libelle,type,position"; +$tabfieldinsert[6] = "code,libelle,type,color,position"; $tabfieldinsert[7] = "code,libelle,fk_pays,accountancy_code,deductible"; $tabfieldinsert[8] = "code,libelle,fk_country"; $tabfieldinsert[9] = "code_iso,label,unicode"; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index b12dc5fb702..ffe07614b7d 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -66,11 +66,12 @@ class ActionComm extends CommonObject var $usertodo; // Object user of owner var $userdone; // Object user that did action (deprecated) + var $socid; + var $contactid; var $societe; // Company linked to action (optional) var $contact; // Contact linked to action (optional) var $fk_project; // Id of project (optional) - // Properties for links to other objects var $fk_element; // Id of record var $elementtype; // Type of record. This if property ->element of object linked to. diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 22f968e2b4a..f6a616d3496 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -410,6 +410,8 @@ if ($resql) $event->location=$obj->location; $event->transparency=$obj->transparency; + $event->socid=$obj->fk_soc; + $event->contactid=$obj->fk_contact; $event->societe->id=$obj->fk_soc; $event->contact->id=$obj->fk_contact; @@ -779,7 +781,7 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & } //$cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd; - // Show rect of event + // Define all rects with event (cases1 is first half hour, cases2 is second half hour) for ($h = $begin_h; $h < $end_h; $h++) { $color = ''; //init @@ -797,12 +799,22 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & $busy=$event->transparency; $cases1[$h][$event->id]['busy']=$busy; $cases1[$h][$event->id]['string']=dol_print_date($event->date_start_in_calendar,'dayhour').' - '.dol_print_date($event->date_end_in_calendar,'dayhour').' - '.$event->label; + $cases1[$h][$event->id]['typecode']=$event->type_code; + if ($event->socid) + { + $cases1[$h][$event->id]['string'].='xxx'; + } } if ($event->date_start_in_calendar < $c && $dateendtouse > $b) { $busy=$event->transparency; $cases2[$h][$event->id]['busy']=$busy; $cases2[$h][$event->id]['string']=dol_print_date($event->date_start_in_calendar,'dayhour').' - '.dol_print_date($event->date_end_in_calendar,'dayhour').' - '.$event->label; + $cases1[$h][$event->id]['typecode']=$event->type_code; + if ($event->socid) + { + $cases2[$h][$event->id]['string'].='xxx'; + } } } else @@ -812,6 +824,8 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & $cases2[$h][$event->id]['busy']=$busy; $cases1[$h][$event->id]['string']=$event->label; $cases2[$h][$event->id]['string']=$event->label; + $cases1[$h][$event->id]['typecode']=$event->type_code; + $cases2[$h][$event->id]['typecode']=$event->type_code; break; } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 08f384612f7..0233706928c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -804,8 +804,10 @@ class Form // Construct $out and $outarray $out.= 'attribute_required [$key])) - print ' class="fieldrequired"'; + if (! empty($extrafields->attribute_required [$key])) print ' class="fieldrequired"'; print '>' . $label . ''; - $colspan='0'; - } - else - { - $out .= ''; - } - // Convert date into timestamp format - if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) - { - $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$this->db->jdate($this->array_options['options_'.$key]); - } - - if($extrafields->attribute_required[$key]) - $label = ''.$label.''; - - $out .= ''; - $out .=''; - - switch($mode) { - case "view": - $out .= $extrafields->showOutputField($key,$value); - break; - case "edit": - $out .= $extrafields->showInputField($key,$value,'',$keyprefix); - break; - } - - $out .= ''."\n"; - - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= ''; - else $out .= ''; - $e++; - } - } - $out .= "\n"; - $out .= ' '; - $out .= ' - '; - } - return $out; - } - - /** * Function to check if an object is used by others. * Check is done into this->childtables. There is no check into llx_element_element. @@ -3473,38 +3152,6 @@ abstract class CommonObject } } - /** - * Call trigger based on this instance - * NB: Error from trigger are stacked in interface->errors - * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. - * - * @param string $trigger_name trigger's name to execute - * @param User $user Object user - * @return int Result of run_triggers - */ - function call_trigger($trigger_name, $user) - { - global $langs,$conf; - - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); - - if ($result < 0) - { - if (!empty($this->errors)) - { - $this->errors=array_merge($this->errors,$interface->errors); - } - else - { - $this->errors=$interface->errors; - } - } - - return $result; - } - /** * Common function for all objects extending CommonObject for generating documents * @@ -3597,4 +3244,366 @@ abstract class CommonObject } } + + /* Functions common to commonobject and commonobjectline */ + + + /* For triggers */ + + + /** + * Call trigger based on this instance + * NB: Error from trigger are stacked in interface->errors + * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. + * + * @param string $trigger_name trigger's name to execute + * @param User $user Object user + * @return int Result of run_triggers + */ + function call_trigger($trigger_name, $user) + { + global $langs,$conf; + + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); + + if ($result < 0) + { + if (!empty($this->errors)) + { + $this->errors=array_merge($this->errors,$interface->errors); + } + else + { + $this->errors=$interface->errors; + } + } + + return $result; + } + + + /* Functions for extrafields */ + + + /** + * Function to get extra fields of a member into $this->array_options + * This method is in most cases called by method fetch of objects but you can call it separately. + * + * @param int $rowid Id of line + * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label() + * @return int <0 if error, 0 if no optionals to find nor found, 1 if a line is found and optional loaded + */ + function fetch_optionals($rowid='',$optionsArray='') + { + if (empty($rowid)) $rowid=$this->id; + + if (! is_array($optionsArray)) + { + // optionsArray not already loaded, so we load it + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields = new ExtraFields($this->db); + $optionsArray = $extrafields->fetch_name_optionals_label($this->table_element); + } + + // Request to get complementary values + if (count($optionsArray) > 0) + { + $sql = "SELECT rowid"; + foreach ($optionsArray as $name => $label) + { + $sql.= ", ".$name; + } + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; + $sql.= " WHERE fk_object = ".$rowid; + + dol_syslog(get_class($this)."::fetch_optionals", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $numrows=$this->db->num_rows($resql); + if ($numrows) + { + $tab = $this->db->fetch_array($resql); + + foreach ($tab as $key => $value) + { + // Test fetch_array ! is_int($key) because fetch_array seult is a mix table with Key as alpha and Key as int (depend db engine) + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) + { + // we can add this attribute to adherent object + $this->array_options["options_".$key]=$value; + } + } + } + + $this->db->free($resql); + + if ($numrows) return $numrows; + else return 0; + } + else + { + dol_print_error($this->db); + return -1; + } + } + return 0; + } + + /** + * Delete all extra fields values for the current object. + * + * @return int <0 if KO, >0 if OK + */ + function deleteExtraFields() + { + global $langs; + + $error=0; + + $this->db->begin(); + + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; + dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); + $resql=$this->db->query($sql_del); + if (! $resql) + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + else + { + $this->db->commit(); + return 1; + } + } + + /** + * Add/Update all extra fields values for the current object. + * All data to describe values to insert are stored into $this->array_options=array('keyextrafield'=>'valueextrafieldtoadd') + * + * @return int -1=error, O=did nothing, 1=OK + */ + function insertExtraFields() + { + global $conf,$langs; + + $error=0; + + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used + + if (! empty($this->array_options)) + { + // Check parameters + $langs->load('admin'); + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields = new ExtraFields($this->db); + $optionsArray = $extrafields->fetch_name_optionals_label($this->table_element); + + foreach($this->array_options as $key => $value) + { + $attributeKey = substr($key,8); // Remove 'options_' prefix + $attributeType = $extrafields->attribute_type[$attributeKey]; + $attributeSize = $extrafields->attribute_size[$attributeKey]; + $attributeLabel = $extrafields->attribute_label[$attributeKey]; + switch ($attributeType) + { + case 'int': + if (!is_numeric($value) && $value!='') + { + $error++; $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); + return -1; + } + elseif ($value=='') + { + $this->array_options[$key] = null; + } + break; + case 'price': + $this->array_options[$key] = price2num($this->array_options[$key]); + break; + case 'date': + $this->array_options[$key]=$this->db->idate($this->array_options[$key]); + break; + case 'datetime': + $this->array_options[$key]=$this->db->idate($this->array_options[$key]); + break; + } + } + $this->db->begin(); + + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; + dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); + $this->db->query($sql_del); + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object"; + foreach($this->array_options as $key => $value) + { + $attributeKey = substr($key,8); // Remove 'options_' prefix + // Add field of attribut + if ($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate + $sql.=",".$attributeKey; + } + $sql .= ") VALUES (".$this->id; + foreach($this->array_options as $key => $value) + { + $attributeKey = substr($key,8); // Remove 'options_' prefix + // Add field o fattribut + if($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate) + { + if ($this->array_options[$key] != '') + { + $sql.=",'".$this->db->escape($this->array_options[$key])."'"; + } + else + { + $sql.=",null"; + } + } + } + $sql.=")"; + + dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + else + { + $this->db->commit(); + return 1; + } + } + else return 0; + } + + /** + * Function to show lines of extrafields with output datas + * + * @param object $extrafields Extrafield Object + * @param string $mode Show output (view) or input (edit) for extrafield + * @param array $params Optionnal parameters + * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names) + * + * @return string + */ + function showOptionals($extrafields, $mode='view', $params=0, $keyprefix='') + { + global $_POST, $conf; + + $out = ''; + + if (count($extrafields->attribute_label) > 0) + { + $out .= "\n"; + $out .= ' '; + $out .= "\n"; + + $e = 0; + foreach($extrafields->attribute_label as $key=>$label) + { + if (is_array($params) && count($params)>0) { + if (array_key_exists('colspan',$params)) { + $colspan=$params['colspan']; + } + }else { + $colspan='3'; + } + switch($mode) { + case "view": + $value=$this->array_options["options_".$key]; + break; + case "edit": + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$this->array_options["options_".$key]); + break; + } + if ($extrafields->attribute_type[$key] == 'separate') + { + $out .= $extrafields->showSeparator($key); + } + else + { + $csstyle=''; + if (is_array($params) && count($params)>0) { + if (array_key_exists('style',$params)) { + $csstyle=$params['style']; + } + } + if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) + { + $out .= ''; + $colspan='0'; + } + else + { + $out .= ''; + } + // Convert date into timestamp format + if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) + { + $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$this->db->jdate($this->array_options['options_'.$key]); + } + + if($extrafields->attribute_required[$key]) + $label = ''.$label.''; + + $out .= ''; + $out .=''; + + switch($mode) { + case "view": + $out .= $extrafields->showOutputField($key,$value); + break; + case "edit": + $out .= $extrafields->showInputField($key,$value,'',$keyprefix); + break; + } + + $out .= ''."\n"; + + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= ''; + else $out .= ''; + $e++; + } + } + $out .= "\n"; + $out .= ' '; + $out .= ' + '; + } + return $out; + } + } diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 675e1cf0794..c3c8d823a34 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -26,36 +26,12 @@ * Parent class for class inheritance lines of business objects * This class is useless for the moment so no inherit are done on it */ -abstract class CommonObjectLine +abstract class CommonObjectLine extends CommonObject { - /** - * Call trigger based on this instance - * NB: Error from trigger are stacked in interface->errors - * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. - * - * @param string $trigger_name trigger's name to execute - * @param User $user Object user - * @return int Result of run_triggers - */ - function call_trigger($trigger_name, $user) - { - global $langs,$conf; + // TODO - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); - if ($result < 0) - { - if (!empty($this->errors)) - { - $this->errors=array_merge($this->errors,$interface->errors); - } - else - { - $this->errors=$interface->errors; - } - } - return $result; - } + // Currently we need function at end of file CommonObject for all object lines. Should find a way to avoid duplicate code. + + // For the moment we use the extends on CommonObject until PHP min is 5.4 so use Traits. } diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index c56ffc30aea..777732aa192 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -194,7 +194,8 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0; showOptionals($extrafieldsline,'view',array('style'=>$bcdd[$var],'colspan'=>$coldisplay)); } ?> From f6445f9cef7d72a43a71b6dd57f8f6d086bc5e42 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Sep 2014 00:51:36 +0200 Subject: [PATCH 06/10] Fix: Pb into repair function --- htdocs/install/repair.php | 232 ++++++++++++++++++++++++++------------ 1 file changed, 159 insertions(+), 73 deletions(-) diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 47456c21c62..48f4b5a6aa6 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -132,7 +132,7 @@ if ($ok) } } -// Affiche version +// Show database version if ($ok) { $version=$db->getVersion(); @@ -143,12 +143,15 @@ if ($ok) //print ''; } -// Force l'affichage de la progression +// Show wait message print ''; flush(); -// Run repair SQL file +/* Start action here */ + + +// run_sql: Run repair SQL file if ($ok) { $dir = "mysql/migration/"; @@ -191,86 +194,169 @@ if ($ok) } -// Search list of fields declared and list of fields created into databases and create fields missing -$extrafields=new ExtraFields($db); -$listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product', - 'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture', - 'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm', - 'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task'); -foreach($listofmodulesextra as $tablename => $elementtype) +// sync_extrafields: Search list of fields declared and list of fields created into databases and create fields missing +if ($ok) { - // Get list of fields - $tableextra=MAIN_DB_PREFIX.$tablename.'_extrafields'; + $extrafields=new ExtraFields($db); + $listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product', + 'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture', + 'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm', + 'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task'); + foreach($listofmodulesextra as $tablename => $elementtype) + { + // Get list of fields + $tableextra=MAIN_DB_PREFIX.$tablename.'_extrafields'; - // Define $arrayoffieldsdesc - $arrayoffieldsdesc=$extrafields->fetch_name_optionals_label($elementtype); + // Define $arrayoffieldsdesc + $arrayoffieldsdesc=$extrafields->fetch_name_optionals_label($elementtype); - // Define $arrayoffieldsfound - $arrayoffieldsfound=array(); - $resql=$db->DDLDescTable($tableextra); - if ($resql) - { - print '\n"; - } + print "\n"; + } + } } -// Clean data into ecm_directories table -clean_data_ecm_directories(); + +// clean_data_ecm_dir: Clean data into ecm_directories table +if ($ok) +{ + clean_data_ecm_directories(); +} -// Check and clean linked elements -if (GETPOST('clean_linked_elements')) + +/* From here, actions need a parameter */ + + + +// clean_linked_elements: Check and clean linked elements +if ($ok && GETPOST('restore_thirdparties_logos')) +{ + //$exts=array('gif','png','jpg'); + + $ext=''; + //foreach($exts as $ext) + //{ + $sql="SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX."societe as s ORDER BY s.nom"; + $resql=$db->query($sql); + if ($resql) + { + $num=$db->num_rows($resql); + $i=0; + + while($i < $num) + { + $obj=$db->fetch_object($resql); + + /* + $name=preg_replace('/é/','',$obj->name); + $name=preg_replace('/ /','_',$name); + $name=preg_replace('/\'/','',$name); + */ + + $tmp=explode('.',$obj->logo); + $name=$tmp[0]; + if (isset($tmp[1])) $ext='.'.$tmp[1]; + + if (! empty($name)) + { + $filetotest=$dolibarr_main_data_root.'/societe/logos/'.$name.$ext; + $filetotestsmall=$dolibarr_main_data_root.'/societe/logos/thumbs/'.$name.$ext; + $exists=dol_is_file($filetotest); + print 'Check thirdparty '.$obj->rowid.' name='.$obj->name.' logo='.$obj->logo.' file '.$filetotest." exists=".$exists."
\n"; + if ($exists) + { + $filetarget=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/'.$name.$ext; + $filetargetsmall=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs/'.$name.'_small'.$ext; + $existt=dol_is_file($filetarget); + if (! $existt) + { + dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos'); + + print "       -> Copy file ".$filetotest." -> ".$filetarget."
\n"; + dol_copy($filetotest, $filetarget, '', 0); + } + + $existtt=dol_is_file($filetargetsmall); + if (! $existtt) + { + dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs'); + + print "       -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."
\n"; + dol_copy($filetotestsmall, $filetargetsmall, '', 0); + } + } + } + + $i++; + } + } + else + { + $ok=0; + dol_print_error($db); + } + //} +} + + +// clean_linked_elements: Check and clean linked elements +if ($ok && GETPOST('clean_linked_elements')) { // propal => order print "\n"; @@ -292,8 +378,8 @@ if (GETPOST('clean_linked_elements')) } -// Run purge of directory -if (GETPOST('purge')) +// clean_orphelin_dir: Run purge of directory +if ($ok && GETPOST('clean_orphelin_dir')) { $conf->setValues($db); From 40c1b02a6c6a7a43082ab942882e627d9b263396 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Sep 2014 01:15:34 +0200 Subject: [PATCH 07/10] Correction repair.sql --- htdocs/install/mysql/migration/repair.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index 868acf7fff0..fbc1572a2ab 100644 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -142,7 +142,7 @@ update llx_societe set barcode = null where (rowid, barcode) in (select max_rowi drop table tmp_societe_double; -UPDATE llx_projet_task SET fk_task_parent = 0 WHERE fk_task_parent = rowid +UPDATE llx_projet_task SET fk_task_parent = 0 WHERE fk_task_parent = rowid; UPDATE llx_actioncomm set fk_user_action = fk_user_done where fk_user_done > 0 and (fk_user_action is null or fk_user_action = 0); From a4d8739477d4de409f1fdb69bb3b25628f88ec38 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Sep 2014 01:35:29 +0200 Subject: [PATCH 08/10] Qual: Clean a lot of deprecated code --- htdocs/comm/action/card.php | 39 +++++++++---------- htdocs/comm/action/class/actioncomm.class.php | 14 ++++--- htdocs/comm/action/document.php | 19 ++++----- htdocs/projet/class/project.class.php | 2 - htdocs/user/class/user.class.php | 12 ++++-- htdocs/webservices/server_actioncomm.php | 18 ++++----- 6 files changed, 51 insertions(+), 53 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 7ca82a2751e..aef2d5fad3d 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -240,12 +240,15 @@ if ($action == 'add') } $object->note = trim($_POST["note"]); + if (isset($_POST["contactid"])) $object->contact = $contact; + if (GETPOST('socid','int') > 0) { $societe = new Societe($db); $societe->fetch(GETPOST('socid','int')); - $object->societe = $societe; + $object->societe = $societe; // deprecated + $object->thirdparty = $societe; } // Special for module webcal and phenix @@ -359,8 +362,10 @@ if ($action == 'update') $object->priority = $_POST["priority"]; $object->fulldayevent= $_POST["fullday"]?1:0; $object->location = GETPOST('location'); - $object->societe->id = $_POST["socid"]; - $object->contact->id = $_POST["contactid"]; + $object->socid = $_POST["socid"]; + $object->contactid = $_POST["contactid"]; + $object->societe->id = $_POST["socid"]; // deprecated + $object->contact->id = $_POST["contactid"]; // deprecated $object->fk_project = $_POST["projectid"]; $object->note = $_POST["note"]; $object->pnote = $_POST["note"]; @@ -795,22 +800,16 @@ if ($action == 'create') if ($id > 0) { $result1=$object->fetch($id); - $result2=$object->fetch_userassigned(); - $result3=$object->fetch_optionals($id,$extralabels); + $result2=$object->fetch_thirdparty(); + $result3=$object->fetch_userassigned(); + $result4=$object->fetch_optionals($id,$extralabels); - if ($result1 < 0 || $result2 < 0 || $result3 < 0) + if ($result1 < 0 || $result2 < 0 || $result3 < 0 || $result4 < 0) { dol_print_error($db,$object->error); exit; } - $societe = new Societe($db); - if ($object->societe->id) - { - $result=$societe->fetch($object->societe->id); - } - $object->societe = $societe; - if ($object->author->id > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($object->author->id); $object->author=$tmpuser; } if ($object->usermod->id > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($object->usermod->id); $object->usermod=$tmpuser; } if ($object->usertodo->id > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($object->usertodo->id); $object->usertodo=$tmpuser; } @@ -959,12 +958,12 @@ if ($id > 0) print ''; // Contact print ''; } @@ -978,7 +977,7 @@ if ($id > 0) $langs->load("project"); print ''; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index ffe07614b7d..1d7cf0efd68 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -192,10 +192,10 @@ class ActionComm extends CommonObject $sql.= (isset($this->durationp) && $this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null").","; // deprecated $sql.= (isset($this->type_id)?$this->type_id:"null").","; $sql.= (isset($this->code)?" '".$this->code."'":"null").","; - $sql.= (isset($this->societe->id) && $this->societe->id > 0?" '".$this->societe->id."'":"null").","; + $sql.= (isset($this->socid) && $this->socid > 0?" '".$this->socid."'":"null").","; $sql.= (isset($this->fk_project) && $this->fk_project > 0?" '".$this->fk_project."'":"null").","; $sql.= " '".$this->db->escape($this->note)."',"; - $sql.= (isset($this->contact->id) && $this->contact->id > 0?"'".$this->contact->id."'":"null").","; + $sql.= (isset($this->contactid) && $this->contactid > 0?"'".$this->contactid."'":"null").","; $sql.= (isset($user->id) && $user->id > 0 ? "'".$user->id."'":"null").","; $sql.= (isset($this->usertodo->id) && $this->usertodo->id > 0?"'".$this->usertodo->id."'":"null").","; $sql.= (isset($this->userdone->id) && $this->userdone->id > 0?"'".$this->userdone->id."'":"null").","; @@ -358,10 +358,12 @@ class ActionComm extends CommonObject $this->location = $obj->location; $this->transparency = $obj->transparency; - $this->socid = $obj->fk_soc; // To have fetch_thirdparty method working - $this->societe->id = $obj->fk_soc; - $this->contact->id = $obj->fk_contact; - $this->fk_project = $obj->fk_project; + $this->socid = $obj->fk_soc; // To have fetch_thirdparty method working + $this->contactid = $obj->fk_contact; + $this->fk_project = $obj->fk_project; // To have fetch_project method working + + $this->societe->id = $obj->fk_soc; // For backward compatibility + $this->contact->id = $obj->fk_contact; // For backward compatibility $this->fk_element = $obj->fk_element; $this->elementtype = $obj->elementtype; diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php index b000d2017d7..0556e532f35 100644 --- a/htdocs/comm/action/document.php +++ b/htdocs/comm/action/document.php @@ -60,12 +60,7 @@ $object = new ActionComm($db); if ($objectid > 0) { $ret = $object->fetch($objectid); - if ($ret > 0) { - $company=new Societe($db); - $company->fetch($object->societe->id); - $object->societe=$company; // For backward compatibility - $object->thirdparty=$company; - } + $object->fetch_thirdparty(); } // Get parameters @@ -112,7 +107,7 @@ if ($object->id > 0) $now=dol_now(); $delay_warning=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60; - + dol_fiche_head($head, 'documents', $langs->trans("Action"),0,'action'); // Affichage fiche action en mode visu @@ -202,17 +197,17 @@ if ($object->id > 0) print ''; - + print '
'; // Convert date into timestamp format if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) { $value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]); } - if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key) { + if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key) + { print ''; print ''; print ''; @@ -2041,7 +2051,9 @@ if ($action == 'create') print ''; print ''; - } else { + } + else + { print $extrafields->showOutputField($key, $value); if ($object->statut == 0 && $user->rights->propal->creer) print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ''; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index f5d20936052..193443dd64d 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -34,9 +34,9 @@ */ include_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php'; -require_once DOL_DOCUMENT_ROOT .'/product/class/product.class.php'; -require_once DOL_DOCUMENT_ROOT .'/societe/class/client.class.php'; -require_once DOL_DOCUMENT_ROOT .'/margin/lib/margins.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php'; +require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php'; /** @@ -3263,11 +3263,10 @@ class Facture extends CommonInvoice /** - * \class FactureLigne - * \brief Classe permettant la gestion des lignes de factures - * Gere des lignes de la table llx_facturedet + * Class to manage invoice lines. + * Saved into database table llx_facturedet */ -class FactureLigne extends CommonInvoiceLine +class FactureLigne extends CommonInvoiceLine { var $db; var $error; diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index f44efafbffa..90ad3e196e3 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -358,10 +358,14 @@ abstract class CommonInvoice extends CommonObject } } + + +require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php'; + /** * Parent class of all other business classes for details of elements (invoices, contracts, proposals, orders, ...) */ -abstract class CommonInvoiceLine extends CommonObject +abstract class CommonInvoiceLine extends CommonObjectLine { } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 60e59222c9e..e8dcce57ac4 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2153,327 +2153,6 @@ abstract class CommonObject } } - - /** - * Function to get extra fields of a member into $this->array_options - * This method is in most cases called by method fetch of objects but you can call it separately. - * - * @param int $rowid Id of line - * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label() - * @return int <0 if error, 0 if no optionals to find nor found, 1 if a line is found and optional loaded - */ - function fetch_optionals($rowid='',$optionsArray='') - { - if (empty($rowid)) $rowid=$this->id; - - if (! is_array($optionsArray)) - { - // optionsArray not already loaded, so we load it - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafields = new ExtraFields($this->db); - $optionsArray = $extrafields->fetch_name_optionals_label($this->table_element); - } - - // Request to get complementary values - if (count($optionsArray) > 0) - { - $sql = "SELECT rowid"; - foreach ($optionsArray as $name => $label) - { - $sql.= ", ".$name; - } - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; - $sql.= " WHERE fk_object = ".$rowid; - - dol_syslog(get_class($this)."::fetch_optionals", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $numrows=$this->db->num_rows($resql); - if ($numrows) - { - $tab = $this->db->fetch_array($resql); - - foreach ($tab as $key => $value) - { - // Test fetch_array ! is_int($key) because fetch_array seult is a mix table with Key as alpha and Key as int (depend db engine) - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) - { - // we can add this attribute to adherent object - $this->array_options["options_".$key]=$value; - } - } - } - - $this->db->free($resql); - - if ($numrows) return $numrows; - else return 0; - } - else - { - dol_print_error($this->db); - return -1; - } - } - return 0; - } - - /** - * Delete all extra fields values for the current object. - * - * @return int <0 if KO, >0 if OK - */ - function deleteExtraFields() - { - global $langs; - - $error=0; - - $this->db->begin(); - - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; - dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); - $resql=$this->db->query($sql_del); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - else - { - $this->db->commit(); - return 1; - } - } - - /** - * Add/Update all extra fields values for the current object. - * All data to describe values to insert are stored into $this->array_options=array('keyextrafield'=>'valueextrafieldtoadd') - * - * @return int -1=error, O=did nothing, 1=OK - */ - function insertExtraFields() - { - global $conf,$langs; - - $error=0; - - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used - - if (! empty($this->array_options)) - { - // Check parameters - $langs->load('admin'); - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafields = new ExtraFields($this->db); - $optionsArray = $extrafields->fetch_name_optionals_label($this->table_element); - - foreach($this->array_options as $key => $value) - { - $attributeKey = substr($key,8); // Remove 'options_' prefix - $attributeType = $extrafields->attribute_type[$attributeKey]; - $attributeSize = $extrafields->attribute_size[$attributeKey]; - $attributeLabel = $extrafields->attribute_label[$attributeKey]; - switch ($attributeType) - { - case 'int': - if (!is_numeric($value) && $value!='') - { - $error++; $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); - return -1; - } - elseif ($value=='') - { - $this->array_options[$key] = null; - } - break; - case 'price': - $this->array_options[$key] = price2num($this->array_options[$key]); - break; - case 'date': - $this->array_options[$key]=$this->db->idate($this->array_options[$key]); - break; - case 'datetime': - $this->array_options[$key]=$this->db->idate($this->array_options[$key]); - break; - } - } - $this->db->begin(); - - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; - dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); - $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object"; - foreach($this->array_options as $key => $value) - { - $attributeKey = substr($key,8); // Remove 'options_' prefix - // Add field of attribut - if ($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate - $sql.=",".$attributeKey; - } - $sql .= ") VALUES (".$this->id; - foreach($this->array_options as $key => $value) - { - $attributeKey = substr($key,8); // Remove 'options_' prefix - // Add field o fattribut - if($extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate) - { - if ($this->array_options[$key] != '') - { - $sql.=",'".$this->db->escape($this->array_options[$key])."'"; - } - else - { - $sql.=",null"; - } - } - } - $sql.=")"; - - dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - else - { - $this->db->commit(); - return 1; - } - } - else return 0; - } - - /** - * Function to show lines of extrafields with output datas - * - * @param object $extrafields Extrafield Object - * @param string $mode Show output (view) or input (edit) for extrafield - * @param array $params Optionnal parameters - * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names) - * - * @return string - */ - function showOptionals($extrafields, $mode='view', $params=0, $keyprefix='') - { - global $_POST, $conf; - - $out = ''; - - if (count($extrafields->attribute_label) > 0) - { - $out .= "\n"; - $out .= ' '; - $out .= "\n"; - - $e = 0; - foreach($extrafields->attribute_label as $key=>$label) - { - if (is_array($params) && count($params)>0) { - if (array_key_exists('colspan',$params)) { - $colspan=$params['colspan']; - } - }else { - $colspan='3'; - } - switch($mode) { - case "view": - $value=$this->array_options["options_".$key]; - break; - case "edit": - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$this->array_options["options_".$key]); - break; - } - if ($extrafields->attribute_type[$key] == 'separate') - { - $out .= $extrafields->showSeparator($key); - } - else - { - $csstyle=''; - if (is_array($params) && count($params)>0) { - if (array_key_exists('style',$params)) { - $csstyle=$params['style']; - } - } - if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) - { - $out .= '
'.$label.'
'.$label.'
'.join('.',$versionarray).'
'.$langs->trans("PleaseBePatient").'
Check availability of extra field for '.$tableextra."
\n"; - $i=0; - while($obj=$db->fetch_object($resql)) - { - $fieldname=$fieldtype=''; - if (preg_match('/mysql/',$db->type)) - { - $fieldname=$obj->Field; - $fieldtype=$obj->Type; - } - else - { - $fieldname = isset($obj->Key)?$obj->Key:$obj->attname; - $fieldtype = isset($obj->Type)?$obj->Type:'varchar'; - } + // Define $arrayoffieldsfound + $arrayoffieldsfound=array(); + $resql=$db->DDLDescTable($tableextra); + if ($resql) + { + print '
Check availability of extra field for '.$tableextra."
\n"; + $i=0; + while($obj=$db->fetch_object($resql)) + { + $fieldname=$fieldtype=''; + if (preg_match('/mysql/',$db->type)) + { + $fieldname=$obj->Field; + $fieldtype=$obj->Type; + } + else + { + $fieldname = isset($obj->Key)?$obj->Key:$obj->attname; + $fieldtype = isset($obj->Type)?$obj->Type:'varchar'; + } - if (empty($fieldname)) continue; - if (in_array($fieldname,array('rowid','tms','fk_object','import_key'))) continue; - $arrayoffieldsfound[$fieldname]=array('type'=>$fieldtype); - } + if (empty($fieldname)) continue; + if (in_array($fieldname,array('rowid','tms','fk_object','import_key'))) continue; + $arrayoffieldsfound[$fieldname]=array('type'=>$fieldtype); + } - // If it does not match, we create fields - foreach($arrayoffieldsdesc as $code => $label) - { - if (! in_array($code,array_keys($arrayoffieldsfound))) - { - print 'Found field '.$code.' declared into '.MAIN_DB_PREFIX.'extrafields table but not found into desc of table '.$tableextra." -> "; - $type=$extrafields->attribute_type[$code]; $value=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null'; - $field_desc=array( - 'type'=>$type, - 'value'=>$value, - 'attribute'=>$attribute, - 'default'=>$default, - 'extra'=>$extra, - 'null'=>$null - ); - //var_dump($field_desc);exit; + // If it does not match, we create fields + foreach($arrayoffieldsdesc as $code => $label) + { + if (! in_array($code,array_keys($arrayoffieldsfound))) + { + print 'Found field '.$code.' declared into '.MAIN_DB_PREFIX.'extrafields table but not found into desc of table '.$tableextra." -> "; + $type=$extrafields->attribute_type[$code]; $value=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null'; + $field_desc=array( + 'type'=>$type, + 'value'=>$value, + 'attribute'=>$attribute, + 'default'=>$default, + 'extra'=>$extra, + 'null'=>$null + ); + //var_dump($field_desc);exit; - $result=$db->DDLAddField($tableextra,$code,$field_desc,""); - if ($result < 0) - { - print "KO ".$db->lasterror."
\n"; - } - else - { - print "OK
\n"; - } - } - } + $result=$db->DDLAddField($tableextra,$code,$field_desc,""); + if ($result < 0) + { + print "KO ".$db->lasterror."
\n"; + } + else + { + print "OK
\n"; + } + } + } - print "
 
 
".checkLinkedElements('propal', 'commande')."
'; $events=array(); $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); - print $form->select_company($object->societe->id,'socid','',1,1,0,$events); + print $form->select_company($object->thirdparty->id,'socid','',1,1,0,$events); print ''.$langs->trans("Contact").''; - $form->select_contacts($object->societe->id, $object->contact->id,'contactid',1); + $form->select_contacts($object->thirdparty->id, $object->contact->id,'contactid',1); print '
'.$langs->trans("Project").''; - $numprojet=$formproject->select_projects($object->societe->id,$object->fk_project,'projectid'); + $numprojet=$formproject->select_projects($object->thirdparty->id,$object->fk_project,'projectid'); if ($numprojet==0) { print '   '.$langs->trans("AddProject").''; @@ -1152,12 +1151,12 @@ if ($id > 0) // Third party - Contact if ($conf->societe->enabled) { - print '
'.$langs->trans("ActionOnCompany").''.($object->societe->id?$object->societe->getNomUrl(1):$langs->trans("None")); - if ($object->societe->id && $object->type_code == 'AC_TEL') + print '
'.$langs->trans("ActionOnCompany").''.($object->thirdparty->id?$object->thirdparty->getNomUrl(1):$langs->trans("None")); + if (is_object($object->thirdparty) && $object->thirdparty->id > 0 && $object->type_code == 'AC_TEL') { - if ($object->societe->fetch($object->societe->id)) + if ($object->thirdparty->fetch($object->thirdparty->id)) { - print "
".dol_print_phone($object->societe->phone); + print "
".dol_print_phone($object->thirdparty->phone); } } print '
'.$langs->trans("ActionAffectedTo").''; if ($object->usertodo->id > 0) print $object->usertodo->getNomUrl(1); print '


'; // Third party - Contact - print ''; diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 7fb6c6e373a..fb7da8636b2 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -323,8 +323,6 @@ class Project extends CommonObject $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; $this->socid = $obj->fk_soc; - $this->societe=(object)array();// To avoid warning on next line - $this->societe->id = $obj->fk_soc; // TODO For backward compatibility $this->user_author_id = $obj->fk_user_creat; $this->public = $obj->public; $this->statut = $obj->fk_statut; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 5177bb3dbed..72db0966699 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -72,8 +72,10 @@ class User extends CommonObject var $datem; //! If this is defined, it is an external user - var $societe_id; - var $contact_id; + var $societe_id; // deprecated + var $contact_id; // deprecated + var $socid; + var $contactid; var $fk_member; var $fk_user; @@ -237,8 +239,10 @@ class User extends CommonObject $this->datelastlogin = $this->db->jdate($obj->datel); $this->datepreviouslogin = $this->db->jdate($obj->datep); - $this->societe_id = $obj->fk_societe; - $this->contact_id = $obj->fk_socpeople; + $this->societe_id = $obj->fk_societe; // deprecated + $this->contact_id = $obj->fk_socpeople; // deprecated + $this->socid = $obj->fk_societe; + $this->contactid = $obj->fk_socpeople; $this->fk_member = $obj->fk_member; $this->fk_user = $obj->fk_user; diff --git a/htdocs/webservices/server_actioncomm.php b/htdocs/webservices/server_actioncomm.php index d5d9c45fa36..2a41a769314 100644 --- a/htdocs/webservices/server_actioncomm.php +++ b/htdocs/webservices/server_actioncomm.php @@ -433,10 +433,10 @@ function createActionComm($authentication,$actioncomm) $newobject->datep=$actioncomm['datep']; $newobject->datef=$actioncomm['datef']; $newobject->type_code=$actioncomm['type_code']; - $newobject->societe->id=$actioncomm['socid']; + $newobject->socid=$actioncomm['socid']; $newobject->fk_project=$actioncomm['projectid']; $newobject->note=$actioncomm['note']; - $newobject->contact->id=$actioncomm['contactid']; + $newobject->contactid=$actioncomm['contactid']; $newobject->usertodo->id=$actioncomm['usertodo']; $newobject->userdone->id=$actioncomm['userdone']; $newobject->label=$actioncomm['label']; @@ -517,21 +517,21 @@ function updateActionComm($authentication,$actioncomm) if (! $error) { $objectfound=false; - + $object=new ActionComm($db); $result=$object->fetch($actioncomm['id']); - + if (!empty($object->id)) { - + $objectfound=true; $object->datep=$actioncomm['datep']; $object->datef=$actioncomm['datef']; $object->type_code=$actioncomm['type_code']; - $object->societe->id=$actioncomm['socid']; + $object->socid=$actioncomm['socid']; + $object->contactid=$actioncomm['contactid']; $object->fk_project=$actioncomm['projectid']; $object->note=$actioncomm['note']; - $object->contact->id=$actioncomm['contactid']; $object->usertodo->id=$actioncomm['usertodo']; $object->userdone->id=$actioncomm['userdone']; $object->label=$actioncomm['label']; @@ -541,7 +541,7 @@ function updateActionComm($authentication,$actioncomm) $object->location=$actioncomm['location']; $object->fk_element=$actioncomm['fk_element']; $object->elementtype=$actioncomm['elementtype']; - + //Retreive all extrafield for actioncomm // fetch optionals attributes and labels $extrafields=new ExtraFields($db); @@ -551,7 +551,7 @@ function updateActionComm($authentication,$actioncomm) $key='options_'.$key; $object->array_options[$key]=$actioncomm[$key]; } - + $db->begin(); $result=$object->update($fuser); From dad82fa1fa936f9373ca24344349f0633bd4d7b1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Sep 2014 01:36:12 +0200 Subject: [PATCH 09/10] Fix: bad phpunit test case --- test/phpunit/AllTests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index eb3c1a56abb..a8a554ca25d 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -126,7 +126,7 @@ class AllTests require_once dirname(__FILE__).'/ContratTest.php'; $suite->addTestSuite('ContratTest'); - require_once dirname(__FILE__).'/FichInterTest.php'; + require_once dirname(__FILE__).'/FichinterTest.php'; $suite->addTestSuite('FichinterTest'); require_once dirname(__FILE__).'/PropalTest.php'; From cdca651dedf0b209fbd25ee4627883c6ddb940f3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Sep 2014 01:40:16 +0200 Subject: [PATCH 10/10] Doxygen. Ad field color --- htdocs/comm/action/class/cactioncomm.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/action/class/cactioncomm.class.php b/htdocs/comm/action/class/cactioncomm.class.php index 8908b4e2a46..065f01d2091 100644 --- a/htdocs/comm/action/class/cactioncomm.class.php +++ b/htdocs/comm/action/class/cactioncomm.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2014 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 @@ -37,6 +37,7 @@ class CActionComm var $type; var $libelle; var $active; + var $color; var $type_actions=array(); @@ -59,7 +60,7 @@ class CActionComm */ function fetch($id) { - $sql = "SELECT id, code, type, libelle, active"; + $sql = "SELECT id, code, type, libelle, color, active"; $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm"; if (is_numeric($id)) $sql.= " WHERE id=".$id; else $sql.= " WHERE code='".$id."'"; @@ -77,12 +78,13 @@ class CActionComm $this->type = $obj->type; $this->libelle = $obj->libelle; $this->active = $obj->active; + $this->color = $obj->color; $this->db->free($resql); return 1; } else - { + { $this->db->free($resql); return 0; } @@ -95,7 +97,7 @@ class CActionComm } /** - * Return list of event types + * Return list of event types: array(id=>label) or array(code=>label) * * @param int $active 1 or 0 to filter on event state active or not ('' by default = no filter) * @param string $idorcode 'id' or 'code' @@ -111,7 +113,7 @@ class CActionComm $repid = array(); $repcode = array(); - $sql = "SELECT id, code, libelle, module, type"; + $sql = "SELECT id, code, libelle, module, type, color"; $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm"; if ($active != '') $sql.=" WHERE active=".$active; if (! empty($excludetype)) $sql.=($active != ''?" AND":" WHERE")." type <> '".$excludetype."'";
'.$langs->trans("ActionOnCompany").''.($object->societe->id?$object->societe->getNomUrl(1):$langs->trans("None")); - if ($object->societe->id && $object->type_code == 'AC_TEL') + print '
'.$langs->trans("ActionOnCompany").''.($object->thirdparty->id?$object->thirdparty->getNomUrl(1):$langs->trans("None")); + if (is_object($object->thirdparty) && $object->thirdparty->id > 0 && $object->type_code == 'AC_TEL') { - if ($object->societe->fetch($object->societe->id)) + if ($object->thirdparty->fetch($object->thirdparty->id)) { - print "
".dol_print_phone($object->societe->phone); + print "
".dol_print_phone($object->thirdparty->phone); } } print '