Work on multi user for events.
Fix: Modules must be reloaded after migration.
This commit is contained in:
parent
640bf7c34b
commit
7224f64224
@ -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 '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td>';
|
||||
$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 '</td></tr>';
|
||||
@ -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 '<tr><td width="30%" class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td>';
|
||||
if ($object->usertodo->id > 0) print $object->usertodo->getNomUrl(1);
|
||||
//if ($object->usertodo->id > 0) print $object->usertodo->getNomUrl(1);
|
||||
print '<tr><td width="30%" class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td>';
|
||||
$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 '</td></tr>';
|
||||
|
||||
print '</table><br><br><table class="border" width="100%">';
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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.='<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
$out.='<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
|
||||
$out.='<script type="text/javascript" language="javascript">jQuery(document).ready(function () { jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });})</script>';
|
||||
$out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
|
||||
$out.='<input type="submit" class="button" name="'.$action.'assignedtouser" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
|
||||
if ($action == 'view')
|
||||
{
|
||||
$out.='';
|
||||
}
|
||||
else
|
||||
{
|
||||
$out.='<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">';
|
||||
$out.='<script type="text/javascript" language="javascript">jQuery(document).ready(function () { jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });})</script>';
|
||||
$out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
|
||||
$out.='<input type="submit" class="button" name="'.$action.'assignedtouser" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
|
||||
}
|
||||
$assignedtouser=array();
|
||||
if (!empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true);
|
||||
if (count($assignedtouser)) $out.='<br>';
|
||||
$i=0;
|
||||
if (!empty($_SESSION['assignedtouser']))
|
||||
{
|
||||
$assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true);
|
||||
}
|
||||
if (count($assignedtouser) && $action != 'view') $out.='<br>';
|
||||
$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.=' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Remove"), 'delete', '', 0, 1).'" value="'.$userstatic->id.'" class="removedassigned" id="removedassigned_'.$userstatic->id.'" name="removedassigned_'.$userstatic->id.'">';
|
||||
if ($i == 0) { $ownerid = $value['id']; $out.=' ('.$langs->trans("Owner").')'; }
|
||||
if ($i > 0 && $action != 'view') $out.=' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Remove"), 'delete', '', 0, 1).'" value="'.$userstatic->id.'" class="removedassigned" id="removedassigned_'.$userstatic->id.'" name="removedassigned_'.$userstatic->id.'">';
|
||||
//$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional"));
|
||||
//$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy"));
|
||||
$out.='<br>';
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user