Clean code

This commit is contained in:
Laurent Destailleur 2014-10-14 00:27:23 +02:00
parent e42ab9ea84
commit 536b579b35
8 changed files with 62 additions and 45 deletions

View File

@ -287,17 +287,18 @@ if ($action == 'add')
{
unset($_SESSION['assignedtouser']);
if ($user->id != $object->ownerid) $moreparam="&usertodo=-1"; // We force to remove filter so created record is visible when going back to per user view.
$moreparam='';
if ($user->id != $object->ownerid) $moreparam="usertodo=-1"; // We force to remove filter so created record is visible when going back to per user view.
$db->commit();
if (! empty($backtopage))
{
dol_syslog("Back to ".$backtopage.$moreparam);
header("Location: ".$backtopage.$moreparam);
dol_syslog("Back to ".$backtopage.($moreparam?(preg_match('/\?/',$backtopage)?'&'.$moreparam:'?'.$moreparam):''));
header("Location: ".$backtopage.($moreparam?(preg_match('/\?/',$backtopage)?'&'.$moreparam:'?'.$moreparam):''));
}
elseif($idaction)
{
header("Location: ".DOL_URL_ROOT.'/comm/action/card.php?id='.$idaction.$moreparam);
header("Location: ".DOL_URL_ROOT.'/comm/action/card.php?id='.$idaction.($moreparam?'&'.$moreparam:''));
}
else
{
@ -379,8 +380,6 @@ if ($action == 'update')
// Users
$listofuserid=array();
$assignedtouser=(! empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : 0);
if ($assignedtouser) $listofuserid[$assignedtouser]=array('id'=>$assignedtouser, 'mandatory'=>0, 'transparency'=>($user->id == $assignedtouser ? $transparency : '')); // Owner first
if (! empty($_SESSION['assignedtouser'])) // Now concat assigned users
{
// Restore array with key with same value than param 'id'
@ -390,11 +389,18 @@ if ($action == 'update')
if ($val['id'] > 0 && $val['id'] != $assignedtouser) $listofuserid[$val['id']]=$val;
}
}
else {
$assignedtouser=(! empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : 0);
if ($assignedtouser) $listofuserid[$assignedtouser]=array('id'=>$assignedtouser, 'mandatory'=>0, 'transparency'=>($user->id == $assignedtouser ? $transparency : '')); // Owner first
}
$object->userassigned=array(); // Clear old content
$object->userassigned=array(); $object->userownerid=0; // Clear old content
$i=0;
foreach($listofuserid as $key => $val)
{
if ($i == 0) $object->userownerid = $val['id'];
$object->userassigned[$val['id']]=array('id'=>$val['id'], 'mandatory'=>0, 'transparency'=>($user->id == $val['id'] ? $transparency : ''));
$i++;
}
if (! empty($conf->global->AGENDA_ENABLE_DONEBY))
@ -1070,7 +1076,7 @@ if ($id > 0)
$listofuserid=array();
if (empty($donotclearsession))
{
if (is_object($object->userownerid)) $listofuserid[$object->userownerid]=array('id'=>$object->userownerid,'transparency'=>$object->transparency); // Owner first
if ($object->userownerid > 0) $listofuserid[$object->userownerid]=array('id'=>$object->userownerid,'transparency'=>$object->transparency); // Owner first
if (! empty($object->userassigned)) // Now concat assigned users
{
// Restore array with key with same value than param 'id'

View File

@ -543,9 +543,9 @@ class ActionComm extends CommonObject
$sql.= ", datep2 = ".(strval($this->datef)!='' ? "'".$this->db->idate($this->datef)."'" : 'null');
$sql.= ", durationp = ".(isset($this->durationp) && $this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null"); // deprecated
$sql.= ", note = ".($this->note ? "'".$this->db->escape($this->note)."'":"null");
$sql.= ", fk_soc =". ($this->socid > 0 ? "'".$this->socid."'":"null");
$sql.= ", fk_project =". ($this->fk_project > 0 ? "'".$this->fk_project."'":"null");
$sql.= ", fk_contact =". ($contactid > 0 ? "'".$this->contactid."'":"null");
$sql.= ", fk_soc =". ($socid > 0 ? "'".$socid."'":"null");
$sql.= ", fk_contact =". ($contactid > 0 ? "'".$contactid."'":"null");
$sql.= ", priority = '".$this->priority."'";
$sql.= ", fulldayevent = '".$this->fulldayevent."'";
$sql.= ", location = ".($this->location ? "'".$this->db->escape($this->location)."'":"null");

View File

@ -219,10 +219,10 @@ if (empty($action) || $action=='show_month')
$max_day_in_prev_month = date("t",dol_mktime(0,0,0,$prev_month,1,$prev_year)); // Nb of days in previous month
$max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year)); // Nb of days in next month
// tmpday is a negative or null cursor to know how many days before the 1 to show on month view (if tmpday=0 we start on monday)
$tmpday = -date("w",dol_mktime(0,0,0,$month,1,$year))+2;
// tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
$tmpday = -date("w",dol_mktime(12,0,0,$month,1,$year,true))+2; // date('w') is 0 fo sunday
$tmpday+=((isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)-1);
if ($tmpday >= 1) $tmpday -= 7;
if ($tmpday >= 1) $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
$firstdaytoshow=dol_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$tmpday,$prev_year);
$next_day=7 - ($max_day_in_month+1-$tmpday) % 7;
@ -918,7 +918,7 @@ if (empty($action) || $action == 'show_month') // View by month
echo " <tr>\n";
for ($iter_day = 0; $iter_day < 7; $iter_day++)
{
/* Show days before the beginning of the current month (previous month) */
/* Show days before the beginning of the current month (previous month) */
if ($tmpday <= 0)
{
$style='cal_other_month cal_past';
@ -931,21 +931,20 @@ if (empty($action) || $action == 'show_month') // View by month
elseif ($tmpday <= $max_day_in_month)
{
$curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
$style='cal_current_month';
if ($iter_day == 6) $style.=' cal_current_month_right';
$today=0;
if ($todayarray['mday']==$tmpday && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
if ($today) $style='cal_today';
if ($curtime < $todaytms) $style.=' cal_past';
//var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
echo ' <td class="'.$style.' nowrap" width="14%" valign="top">';
show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
echo " </td>\n";
}
/* Show days after the current month (next month) */
else
{
{
$style='cal_other_month';
if ($iter_day == 6) $style.=' cal_other_month_right';
echo ' <td class="'.$style.' nowrap" width="14%" valign="top">';

View File

@ -956,7 +956,8 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, &
//$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
if (count($cases1[$h]) > 1) $title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
$string1='&nbsp;';
$style1='peruser_notbusy';
if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style1='peruser_notbusy';
else $style1='peruser_busy';
foreach($cases1[$h] as $id => $ev)
{
if ($ev['busy']) $style1='peruser_busy';
@ -967,7 +968,8 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, &
//$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
if (count($cases2[$h]) > 1) $title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
$string2='&nbsp;';
$style2='peruser_notbusy';
if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style2='peruser_notbusy';
else $style2='peruser_busy';
foreach($cases2[$h] as $id => $ev)
{
if ($ev['busy']) $style2='peruser_busy';

View File

@ -1200,8 +1200,10 @@ else if ($action == 'down' && $user->rights->propal->creer) {
$action = 'edit_extras';
}
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) {
if ($action == 'addcontact') {
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer)
{
if ($action == 'addcontact')
{
if ($object->id > 0) {
$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
$result = $object->add_contact($contactid, $_POST ["type"], $_POST ["source"]);

View File

@ -1775,8 +1775,10 @@ else if ($action == 'print_file' and $user->rights->printipp->read) {
$action = '';
}
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer) {
if ($action == 'addcontact') {
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer)
{
if ($action == 'addcontact')
{
$result = $object->fetch($id);
if ($result > 0 && $id > 0) {
@ -3324,12 +3326,13 @@ if ($action == 'create')
// Other attributes (TODO Move this into an include)
$res = $object->fetch_optionals($object->id, $extralabels);
$parameters = array('colspan' => ' colspan="2"');
$parameters = array('colspan' => ' colspan="5"', "cols" => 5);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
// hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) {
foreach ($extrafields->attribute_label as $key => $label) {
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
foreach ($extrafields->attribute_label as $key => $label)
{
if ($action == 'edit_extras') {
$value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options ["options_" . $key]);
} else {

View File

@ -156,7 +156,7 @@ abstract class CommonObject
* Add a link between element $this->element and a contact
*
* @param int $fk_socpeople Id of contact to link
* @param int $type_contact Type of contact (code or id)
* @param int $type_contact Type of contact (code or id). For example: SALESREPFOLL
* @param int $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
* @param int $notrigger Disable all triggers
* @return int <0 if KO, >0 if OK
@ -192,9 +192,10 @@ abstract class CommonObject
// On recherche id type_contact
$sql = "SELECT tc.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
$sql.= " WHERE element='".$this->element."'";
$sql.= " AND source='".$source."'";
$sql.= " AND code='".$type_contact."' AND active=1";
$sql.= " WHERE tc.element='".$this->element."'";
$sql.= " AND tc.source='".$source."'";
$sql.= " AND tc.code='".$type_contact."' AND tc.active=1";
//print $sql;
$resql=$this->db->query($sql);
if ($resql)
{
@ -337,12 +338,14 @@ abstract class CommonObject
/**
* Delete all links between an object $this and all its contacts
*
* @return int >0 if OK, <0 if KO
* @param string $source '' or 'internal' or 'external'
* @param string $code Type of contact (code or id)
* @return int >0 if OK, <0 if KO
*/
function delete_linked_contact()
function delete_linked_contact($source='',$code='')
{
$temp = array();
$typeContact = $this->liste_type_contact('');
$typeContact = $this->liste_type_contact($source,'',0,0,$code);
foreach($typeContact as $key => $value)
{
@ -351,7 +354,7 @@ abstract class CommonObject
$listId = implode(",", $temp);
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
$sql.= " WHERE element_id =".$this->id;
$sql.= " WHERE element_id = ".$this->id;
$sql.= " AND fk_c_type_contact IN (".$listId.")";
dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG);
@ -360,7 +363,7 @@ abstract class CommonObject
return 1;
}
else
{
{
$this->error=$this->db->lasterror();
return -1;
}
@ -478,21 +481,23 @@ abstract class CommonObject
* @param string $source 'internal', 'external' or 'all'
* @param string $order Sort order by : 'code' or 'rowid'
* @param string $option 0=Return array id->label, 1=Return array code->label
* @param string $activeonly 0=all type of contact, 1=only the active
* @param string $activeonly 0=all status of contact, 1=only the active
* @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE')
* @return array Array list of type of contacts (id->label if option=0, code->label if option=1)
*/
function liste_type_contact($source='internal', $order='code', $option=0, $activeonly=0)
function liste_type_contact($source='internal', $order='', $option=0, $activeonly=0, $code='')
{
global $langs;
if (empty($order)) $order='code';
$tab = array();
$sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
$sql.= " WHERE tc.element='".$this->element."'";
if ($activeonly == 1)
$sql.= " AND tc.active=1"; // only the active type
if (! empty($source)) $sql.= " AND tc.source='".$source."'";
if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active type
if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$source."'";
if (! empty($code)) $sql.= " AND tc.code='".$code."'";
$sql.= " ORDER by tc.".$order;
//print "sql=".$sql;

View File

@ -2365,9 +2365,9 @@ table.cal_month { border-spacing: 0px; }
.cal_past_month { opacity: 0.6; background: #EEEEEE; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_current_month { background: #FFFFFF; border-left: solid 1px #E0E0E0; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_current_month_peruserleft { background: #FFFFFF; border-left: solid 3px #6C7C7B; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_today { background: #FFFFF0; border-left: solid 1px #E0E0E0; border-bottom: solid 1px #E0E0E0; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_today_peruser { background: #FFFFF0; border-right: solid 1px #E0E0E0; border-bottom: solid 1px #A0A0A0; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_today_peruser_peruserleft { background: #FFFFF0; border-left: solid 3px #6C7C7B; border-right: solid 1px #E0E0E0; border-bottom: solid 1px #A0A0A0; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_today { background: #FDFDF0; border-left: solid 1px #E0E0E0; border-bottom: solid 1px #E0E0E0; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_today_peruser { background: #FDFDF0; border-right: solid 1px #E0E0E0; border-bottom: solid 1px #E0E0E0; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_today_peruser_peruserleft { background: #FDFDF0; border-left: solid 3px #6C7C7B; border-right: solid 1px #E0E0E0; border-bottom: solid 1px #E0E0E0; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
.cal_past { }
.cal_peruser { padding: 0px; }
.peruser_busy { background: #CC8888; }