Example #1
0
 protected function handleRequest(array $request)
 {
     $listId = $request[self::FIELD_LIST_ID];
     $title = $request[self::FIELD_TITLE];
     $description = $request[self::FIELD_DESCRIPTION];
     $beforeId = $request[self::FIELD_BEFORE_TASK_ID];
     if (isset($request[self::FIELD_AFTER_LAST_OPEN])) {
         if ($request[self::FIELD_AFTER_LAST_OPEN]) {
             $beforeId = Task::findNextTaskIdAfterLastOpenTask($listId);
         }
     }
     TasksList::lock($listId);
     $ord = null;
     if ($beforeId) {
         $beforeTask = Task::fetch($beforeId);
         if ($beforeTask->getListId() !== $listId) {
             throw new Exception("Insertion point for a new task is in another list", EndPoint::STATUS_BAD_REQUEST);
         }
         $ord = $beforeTask->getOrd();
         Task::shiftRight($listId, $ord);
     } else {
         $ord = Task::getNextOrd($listId);
     }
     $taskId = Task::create($listId, $ord, $title, $description);
     return array(self::FIELD_TASK_ID => $taskId);
 }
Example #2
0
 protected function handleRequest(array $request)
 {
     $taskId = $request[self::FIELD_TASK_ID];
     $task = Task::fetch($taskId);
     $listId = $task->getListId();
     TasksList::lock($listId);
     Task::erase($taskId);
     Task::shiftLeft($listId, $task->getOrd());
 }
Example #3
0
 static function getNumberRejectedTasks($userid)
 {
     $task = new Task();
     $qry = 'select count(t.id) as number ' . 'from task t ' . 'where t.userid = ' . $userid . ' and t.status = -1';
     $task->query($qry);
     if ($task->fetch()) {
         $number = $task->number;
     }
     return $number;
 }
Example #4
0
function _updateTimeTask(&$db, $id_task, $fk_user, $ref_task, $duration, $progress, $desc, $label_task, $progress)
{
    global $user;
    $task = new Task($db);
    $task->id = $id_task;
    $task->ref = $ref_task;
    $task->label = $label_task;
    $task->duration_effective = $duration * 3600;
    //duration est en heures dans le webservice et en secondes en bd
    $task->progress = $progress;
    $r = $task->fetch($id_task, $ref_task);
    if ($r > 0) {
        $task->addTimeSpent($user);
    } else {
        exit("taskCantBeFetched =>" . $ref_task);
    }
}
function visu_project_task(&$db, $fk_project_task, $mode, $name)
{
    if (!$fk_project_task) {
        return ' - ';
    }
    require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php';
    require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
    $projectTask = new Task($db);
    $projectTask->fetch($fk_project_task);
    $link = '<a href="' . DOL_URL_ROOT . '/projet/tasks/task.php?id=' . $fk_project_task . '">' . img_picto('', 'object_projecttask.png') . $projectTask->ref . '</a>';
    if ($projectTask->progress == 0) {
        $imgStatus = img_picto('En attente', 'statut0.png');
    } elseif ($projectTask->progress < 100) {
        $imgStatus = img_picto('En cours', 'statut3.png');
    } else {
        $imgStatus = img_picto('Terminée', 'statut4.png');
    }
    if ($mode == 'edit') {
        $formother = new FormOther($db);
        return $link . ' - ' . $formother->select_percent($projectTask->progress, $name) . ' ' . $imgStatus;
    } else {
        return $link . ' - ' . $projectTask->progress . ' % ' . $imgStatus;
    }
}
Example #6
0
 protected function handleRequest(array $request)
 {
     $taskId = $request[self::FIELD_TASK_ID];
     $dstListId = $request[self::FIELD_LIST_ID];
     $beforeTaskId = $request[self::FIELD_BEFORE_TASK_ID];
     if (isset($request[self::FIELD_AFTER_LAST_OPEN])) {
         if ($request[self::FIELD_AFTER_LAST_OPEN]) {
             $beforeTaskId = Task::findNextTaskIdAfterLastOpenTask($dstListId);
         }
     }
     $task = Task::fetch($taskId);
     $srcListId = $task->getListId();
     if ($srcListId !== $dstListId) {
         $srcList = TasksList::fetch($srcListId);
         $dstList = TasksList::fetch($dstListId);
         if ($srcList->getProjectId() !== $dstList->getProjectId()) {
             throw new Exception("Insertion point for a task is in another project list", EndPoint::STATUS_BAD_REQUEST);
         }
     }
     TasksList::lock($srcListId, $dstListId);
     if ($beforeTaskId) {
         Task::shiftLeft($srcListId, $task->getOrd());
         if ($beforeTaskId === $taskId) {
             throw new Exception("Can't move task before itself", EmdPoint::STATUS_BAD_REQUEST);
         }
         $beforeTask = Task::fetch($beforeTaskId);
         if ($beforeTask->getListId() !== $dstListId) {
             throw new Exception("Insertion point for a task is not in destination list", EndPoint::STATUS_BAD_REQUEST);
         }
         Task::shiftRight($dstListId, $beforeTask->getOrd());
         Task::updateListAndOrd($taskId, $dstListId, $beforeTask->getOrd());
     } else {
         Task::shiftLeft($srcListId, $task->getOrd());
         Task::updateListAndOrd($taskId, $dstListId, Task::getNextOrd($dstListId));
     }
 }
Example #7
0
                if ($id > 0) {
                    // We store HOURS in seconds
                    if ($matches[2] == 'hour') {
                        $timespent_duration[$id] += $time * 60 * 60;
                    }
                    // We store MINUTES in seconds
                    if ($matches[2] == 'min') {
                        $timespent_duration[$id] += $time * 60;
                    }
                }
            }
        }
    }
    if (count($timespent_duration) > 0) {
        foreach ($timespent_duration as $key => $val) {
            $task->fetch($key);
            $task->progress = GETPOST($key . 'progress', 'int');
            $task->timespent_duration = $val;
            $task->timespent_fk_user = $user->id;
            $task->timespent_date = dol_mktime(12, 0, 0, $_POST["{$key}month"], $_POST["{$key}day"], $_POST["{$key}year"]);
            $task->addTimeSpent($user);
        }
        setEventMessage($langs->trans("RecordSaved"));
        // Redirect to avoid submit twice on back
        header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $projectid . ($mode ? '&mode=' . $mode : ''));
        exit;
    } else {
        setEventMessage($langs->trans("ErrorTimeSpentIsEmpty"), 'errors');
    }
}
/*
 /**
  *	Function to build a document on disk using the generic odt module.
  *
  *	@param	Commande	$object					Object source to build document
  *	@param	Translate	$outputlangs			Lang output object
  * 	@param	string		$srctemplatepath	    Full path of source filename for generator using a template file
  *	@return	int         						1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs, $srctemplatepath)
 {
     global $user, $langs, $conf, $mysoc, $hookmanager;
     if (empty($srctemplatepath)) {
         dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
         return -1;
     }
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     $sav_charset_output = $outputlangs->charset_output;
     $outputlangs->charset_output = 'UTF-8';
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("projects");
     if ($conf->projet->dir_output) {
         // If $object is id instead of object
         if (!is_object($object)) {
             $id = $object;
             $object = new Task($this->db);
             $result = $object->fetch($id);
             if ($result < 0) {
                 dol_print_error($this->db, $object->error);
                 return -1;
             }
         }
         $project = new Project($this->db);
         $project->fetch($object->fk_project);
         $dir = $conf->projet->dir_output . "/" . $project->ref . "/";
         $objectref = dol_sanitizeFileName($object->ref);
         if (!preg_match('/specimen/i', $objectref)) {
             $dir .= "/" . $objectref;
         }
         $file = $dir . "/" . $objectref . ".odt";
         if (!file_exists($dir)) {
             print '$dir' . $dir;
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return -1;
             }
         }
         if (file_exists($dir)) {
             //print "srctemplatepath=".$srctemplatepath;	// Src filename
             $newfile = basename($srctemplatepath);
             $newfiletmp = preg_replace('/\\.(ods|odt)/i', '', $newfile);
             $newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
             $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
             $newfiletmp = $objectref . '_' . $newfiletmp;
             //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
             $file = $dir . '/' . $newfiletmp . '.odt';
             //print "newdir=".$dir;
             //print "newfile=".$newfile;
             //print "file=".$file;
             //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
             dol_mkdir($conf->projet->dir_temp);
             $socobject = $object->thirdparty;
             // Make substitution
             $substitutionarray = array('__FROM_NAME__' => $this->emetteur->name, '__FROM_EMAIL__' => $this->emetteur->email);
             complete_substitutions_array($substitutionarray, $langs, $object);
             // Open and load template
             require_once ODTPHP_PATH . 'odf.php';
             try {
                 $odfHandler = new odf($srctemplatepath, array('PATH_TO_TMP' => $conf->projet->dir_temp, 'ZIP_PROXY' => 'PclZipProxy', 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}'));
             } catch (Exception $e) {
                 $this->error = $e->getMessage();
                 return -1;
             }
             // After construction $odfHandler->contentXml contains content and
             // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
             // [!-- BEGIN lines --]*[!-- END lines --]
             //print html_entity_decode($odfHandler->__toString());
             //print exit;
             // Make substitutions into odt of user info
             $array_user = $this->get_substitutionarray_user($user, $outputlangs);
             $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
             $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
             $array_objet = $this->get_substitutionarray_object($project, $outputlangs);
             $array_other = $this->get_substitutionarray_other($outputlangs);
             $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_objet, $array_other);
             complete_substitutions_array($tmparray, $outputlangs, $object);
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Replace tags of lines for tasks
             try {
                 // Security check
                 $socid = 0;
                 if (!empty($project->fk_soc)) {
                     $socid = $project->fk_soc;
                 }
                 $tmparray = $this->get_substitutionarray_tasks($object, $outputlangs);
                 complete_substitutions_array($tmparray, $outputlangs, $object);
                 foreach ($tmparray as $key => $val) {
                     try {
                         $odfHandler->setVars($key, $val, true, 'UTF-8');
                     } catch (OdfException $e) {
                     } catch (SegmentException $e) {
                     }
                 }
                 // Replace tags of lines for contacts task
                 $sourcearray = array('internal', 'external');
                 $contact_arrray = array();
                 foreach ($sourcearray as $source) {
                     $contact_temp = $object->liste_contact(-1, $source);
                     if (is_array($contact_temp) && count($contact_temp) > 0) {
                         $contact_arrray = array_merge($contact_arrray, $contact_temp);
                     }
                 }
                 if (is_array($contact_arrray) && count($contact_arrray) > 0) {
                     $listlinestaskres = $odfHandler->setSegment('tasksressources');
                     foreach ($contact_arrray as $contact) {
                         if ($contact['source'] == 'internal') {
                             $objectdetail = new User($this->db);
                             $objectdetail->fetch($contact['id']);
                             $contact['socname'] = $mysoc->name;
                         } elseif ($contact['source'] == 'external') {
                             $objectdetail = new Contact($this->db);
                             $objectdetail->fetch($contact['id']);
                             $soc = new Societe($this->db);
                             $soc->fetch($contact['socid']);
                             $contact['socname'] = $soc->name;
                         }
                         $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1);
                         $tmparray = $this->get_substitutionarray_tasksressource($contact, $outputlangs);
                         foreach ($tmparray as $key => $val) {
                             try {
                                 $listlinestaskres->setVars($key, $val, true, 'UTF-8');
                             } catch (OdfException $e) {
                             } catch (SegmentException $e) {
                             }
                         }
                         $listlinestaskres->merge();
                     }
                     $odfHandler->mergeSegment($listlinestaskres);
                 }
                 //Time ressources
                 $sql = "SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note";
                 $sql .= ", u.name, u.firstname";
                 $sql .= " FROM " . MAIN_DB_PREFIX . "projet_task_time as t";
                 $sql .= " , " . MAIN_DB_PREFIX . "user as u";
                 $sql .= " WHERE t.fk_task =" . $object->id;
                 $sql .= " AND t.fk_user = u.rowid";
                 $sql .= " ORDER BY t.task_date DESC";
                 $resql = $this->db->query($sql);
                 if ($resql) {
                     $num = $this->db->num_rows($resql);
                     $i = 0;
                     $tasks = array();
                     $listlinestasktime = $odfHandler->setSegment('taskstimes');
                     while ($i < $num) {
                         $row = $this->db->fetch_array($resql);
                         if (!empty($row['fk_user'])) {
                             $objectdetail = new User($this->db);
                             $objectdetail->fetch($row['fk_user']);
                             $row['fullcivname'] = $objectdetail->getFullName($outputlangs, 1);
                         } else {
                             $row['fullcivname'] = '';
                         }
                         $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs);
                         foreach ($tmparray as $key => $val) {
                             try {
                                 $listlinestasktime->setVars($key, $val, true, 'UTF-8');
                             } catch (OdfException $e) {
                             } catch (SegmentException $e) {
                             }
                         }
                         $listlinestasktime->merge();
                         $i++;
                     }
                     $this->db->free($resql);
                     $odfHandler->mergeSegment($listlinestasktime);
                 }
                 // Replace tags of project files
                 $listtasksfiles = $odfHandler->setSegment('tasksfiles');
                 $upload_dir = $conf->projet->dir_output . '/' . dol_sanitizeFileName($project->ref) . '/' . dol_sanitizeFileName($object->ref);
                 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', 'name', SORT_ASC, 1);
                 foreach ($filearray as $filedetail) {
                     $tmparray = $this->get_substitutionarray_task_file($filedetail, $outputlangs);
                     //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true));
                     foreach ($tmparray as $key => $val) {
                         try {
                             $listtasksfiles->setVars($key, $val, true, 'UTF-8');
                         } catch (OdfException $e) {
                         } catch (SegmentException $e) {
                         }
                     }
                     $listtasksfiles->merge();
                 }
                 //$listlines->merge();
                 $odfHandler->mergeSegment($listtasksfiles);
             } catch (OdfException $e) {
                 $this->error = $e->getMessage();
                 dol_syslog($this->error, LOG_WARNING);
                 return -1;
             }
             // Replace tags of project files
             try {
                 $listlines = $odfHandler->setSegment('projectfiles');
                 $upload_dir = $conf->projet->dir_output . '/' . dol_sanitizeFileName($object->ref);
                 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', 'name', SORT_ASC, 1);
                 foreach ($filearray as $filedetail) {
                     //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true));
                     $tmparray = $this->get_substitutionarray_project_file($filedetail, $outputlangs);
                     foreach ($tmparray as $key => $val) {
                         try {
                             $listlines->setVars($key, $val, true, 'UTF-8');
                         } catch (OdfException $e) {
                         } catch (SegmentException $e) {
                         }
                     }
                     $listlines->merge();
                 }
                 $odfHandler->mergeSegment($listlines);
             } catch (OdfException $e) {
                 $this->error = $e->getMessage();
                 dol_syslog($this->error, LOG_WARNING);
                 return -1;
             }
             // Replace tags of lines for contacts
             $sourcearray = array('internal', 'external');
             $contact_arrray = array();
             foreach ($sourcearray as $source) {
                 $contact_temp = $project->liste_contact(-1, $source);
                 if (is_array($contact_temp) && count($contact_temp) > 0) {
                     $contact_arrray = array_merge($contact_arrray, $contact_temp);
                 }
             }
             if (is_array($contact_arrray) && count($contact_arrray) > 0) {
                 try {
                     $listlines = $odfHandler->setSegment('projectcontacts');
                     foreach ($contact_arrray as $contact) {
                         if ($contact['source'] == 'internal') {
                             $objectdetail = new User($this->db);
                             $objectdetail->fetch($contact['id']);
                             $contact['socname'] = $mysoc->name;
                         } elseif ($contact['source'] == 'external') {
                             $objectdetail = new Contact($this->db);
                             $objectdetail->fetch($contact['id']);
                             $soc = new Societe($this->db);
                             $soc->fetch($contact['socid']);
                             $contact['socname'] = $soc->name;
                         }
                         $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1);
                         $tmparray = $this->get_substitutionarray_project_contacts($contact, $outputlangs);
                         foreach ($tmparray as $key => $val) {
                             try {
                                 $listlines->setVars($key, $val, true, 'UTF-8');
                             } catch (OdfException $e) {
                             } catch (SegmentException $e) {
                             }
                         }
                         $listlines->merge();
                     }
                     $odfHandler->mergeSegment($listlines);
                 } catch (OdfException $e) {
                     $this->error = $e->getMessage();
                     dol_syslog($this->error, LOG_WARNING);
                     return -1;
                 }
             }
             // Call the beforeODTSave hook
             $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             // Write new file
             if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
                 try {
                     $odfHandler->exportAsAttachedPDF($file);
                 } catch (Exception $e) {
                     $this->error = $e->getMessage();
                     return -1;
                 }
             } else {
                 try {
                     $odfHandler->saveToDisk($file);
                 } catch (Exception $e) {
                     $this->error = $e->getMessage();
                     return -1;
                 }
             }
             $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             $odfHandler = null;
             // Destroy object
             return 1;
             // Success
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return -1;
         }
     }
     return -1;
 }
Example #9
0
$project=new Project($db);

llxHeader("",$langs->trans("Task"));

$html = new Form($db);

if ($_GET["id"] > 0)
{
	/*
	 * Fiche projet en mode visu
	 */
	$task = new Task($db);
	$projectstatic = new Project($db);
	$userstatic = new User($db);

	if ($task->fetch($_GET["id"]) >= 0 )
	{
		$result=$projectstatic->fetch($task->fk_project);
		if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);

		// To get role of users
		//$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
		//$arrayofuseridoftask=$task->getListContactId('internal');

		$head=task_prepare_head($task);

		dol_fiche_head($head, 'time', $langs->trans("Task"),0,'projecttask');

		if ($mesg) print $mesg.'<br>';

		if ($_GET["action"] == 'deleteline')
Example #10
0
$object = new Task($db);
$extrafields = new ExtraFields($db);
$projectstatic = new Project($db);
// fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
/*
 * Actions
 */
if ($action == 'update' && !$_POST["cancel"] && $user->rights->projet->creer) {
    $error = 0;
    if (empty($_POST["label"])) {
        $error++;
        setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), 'errors');
    }
    if (!$error) {
        $object->fetch($id, $ref);
        $tmparray = explode('_', $_POST['task_parent']);
        $task_parent = $tmparray[1];
        if (empty($task_parent)) {
            $task_parent = 0;
        }
        // If task_parent is ''
        $object->label = $_POST["label"];
        $object->description = $_POST['description'];
        $object->fk_task_parent = $task_parent;
        $object->planned_workload = $planned_workload;
        $object->date_start = dol_mktime($_POST['dateohour'], $_POST['dateomin'], 0, $_POST['dateomonth'], $_POST['dateoday'], $_POST['dateoyear'], 'user');
        $object->date_end = dol_mktime($_POST['dateehour'], $_POST['dateemin'], 0, $_POST['dateemonth'], $_POST['dateeday'], $_POST['dateeyear'], 'user');
        $object->progress = $_POST['progress'];
        // Fill array 'array_options' with data from add form
        $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
Example #11
0
 /**
  *    Shift project task date from current date to delta
  *
  *    @param	timestamp		$old_project_dt_start	old project start date
  *    @return	int				1 if OK or < 0 if KO
  */
 function shiftTaskDate($old_project_dt_start)
 {
     global $user, $langs, $conf;
     $error = 0;
     $taskstatic = new Task($this->db);
     // Security check
     $socid = 0;
     if ($user->societe_id > 0) {
         $socid = $user->societe_id;
     }
     $tasksarray = $taskstatic->getTasksArray(0, 0, $this->id, $socid, 0);
     foreach ($tasksarray as $tasktoshiftdate) {
         $to_update = false;
         // Fetch only if update of date will be made
         if (!empty($tasktoshiftdate->date_start) || !empty($tasktoshiftdate->date_end)) {
             //dol_syslog(get_class($this)."::shiftTaskDate to_update", LOG_DEBUG);
             $to_update = true;
             $task = new Task($this->db);
             $result = $task->fetch($tasktoshiftdate->id);
             if (!$result) {
                 $error++;
                 $this->error .= $task->error;
             }
         }
         //print "$this->date_start + $tasktoshiftdate->date_start - $old_project_dt_start";exit;
         //Calcultate new task start date with difference between old proj start date and origin task start date
         if (!empty($tasktoshiftdate->date_start)) {
             $task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_start);
         }
         //Calcultate new task end date with difference between origin proj end date and origin task end date
         if (!empty($tasktoshiftdate->date_end)) {
             $task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_start);
         }
         if ($to_update) {
             $result = $task->update($user);
             if (!$result) {
                 $error++;
                 $this->error .= $task->error;
             }
         }
     }
     if ($error != 0) {
         return -1;
     }
     return $result;
 }
Example #12
0
/*
 * View
 */

llxHeader("",$langs->trans("Task"));

$html = new Form($db);
$formother = new FormOther($db);
$project = new Project($db);

if ($taskid)
{
	$task = new Task($db);
	$projectstatic = new Project($db);

	if ($task->fetch($taskid) >= 0 )
	{
		$result=$projectstatic->fetch($task->fk_project);
		if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);

		// To verify role of users
		//$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
		//$arrayofuseridoftask=$task->getListContactId('internal');

		if ($mesg) print $mesg;

		$head=task_prepare_head($task);

		dol_fiche_head($head, 'task', $langs->trans("Task"),0,'projecttask');

		if ($_GET["action"] == 'edit' && $user->rights->projet->creer)
Example #13
0
			if(preg_match("/([0-9]+)(hour|min)/",$key,$matches))
			{
				$id = $matches[1];
				
				// We store HOURS in seconds
				if($matches[2]=='hour') $timespent_duration += $time*60*60;

				// We store MINUTES in seconds
				if($matches[2]=='min') $timespent_duration += $time*60;
			}
 		}
	}
	
	if ($timespent_duration > 0)
	{
		$task->fetch($id);
		$task->timespent_duration = $timespent_duration;
		$task->timespent_fk_user = $user->id;
		$task->timespent_date = dol_mktime(12,0,0,$_POST["{$id}month"],$_POST["{$id}day"],$_POST["{$id}year"]);
		$task->addTimeSpent($user);
	}
	else
	{
		$mesg='<div class="error">'.$langs->trans("ErrorTimeSpentIsEmpty").'</div>';
	}
 }

/*
 * View
 */
    /** Overloading the doActions function : replacing the parent's function with the one below 
     *  @param      parameters  meta datas of the hook (context, etc...) 
     *  @param      object             the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...) 
     *  @param      action             current action (if set). Generally create or edit or null 
     *  @return       void 
     */
    function formObjectOptions($parameters, &$object, &$action, $hookmanager)
    {
        global $langs, $db, $conf;
        if ((in_array('ordercard', explode(':', $parameters['context'])) || in_array('propalcard', explode(':', $parameters['context']))) && !empty($conf->of->enabled) && !empty($object->id)) {
            ?>
				<tr>
					<td>Fin de production prévisionnelle</td>
					<td rel="date_fin_prod">
				<?php 
            $is_commande = in_array('ordercard', explode(':', $parameters['context']));
            if ($is_commande) {
                $res = $db->query("SELECT rowid FROM " . MAIN_DB_PREFIX . "assetOf \n\t        \t\tWHERE fk_commande = " . $object->id . " AND status IN ('VALID','OPEN','CLOSE')");
                $TOfId = array();
                while ($obj = $db->fetch_object($res)) {
                    $TOfId[] = $obj->rowid;
                }
                if (!empty($TOfId)) {
                    // l'of existe déjà et est valide
                    $res = $db->query("SELECT MAX(date_estimated_end) as date_estimated_end \n\t\t\t\t\t\t\tFROM " . MAIN_DB_PREFIX . "projet_task t \n\t\t\t\t\t\t\tLEFT JOIN " . MAIN_DB_PREFIX . "projet_task_extrafields tex ON (tex.fk_object=t.rowid)\n\t\t\t\t\t\t\t\tWHERE tex.fk_of IN (" . implode(',', $TOfId) . ")");
                    if ($obj = $db->fetch_object($res)) {
                        $t = strtotime($obj->date_estimated_end);
                        print dol_print_date($t, 'day') . img_info('Temps actuel présent dans l\'ordonnancement. Attention, peut-être revu à tout moment');
                    } else {
                        print 'Pas de tâche ordonnancée ou restant à ordonnancer';
                    }
                } else {
                    print '<a href="javascript:simulOrdo(' . $object->id . ')">Simuler l\'ordonnancement</a>';
                }
            } else {
                print '<a href="javascript:simulOrdo(' . $object->id . ')">Simuler l\'ordonnancement</a>';
            }
            ?>
			<script type="text/javascript">
				function simulOrdo(fk_object) {
					$('td[rel="date_fin_prod"]').html("Patientez svp...");
					$.ajax({
						url:"<?php 
            echo dol_buildpath('/scrumboard/script/interface.php', 1);
            ?>
"
						,data:{
							get:'task-ordo-simulation'
							,fk_object: fk_object
							,type_object : "<?php 
            echo $is_commande ? 'order' : 'propal';
            ?>
"
							
						}
					}).done(function(data) {
						$('td[rel="date_fin_prod"]').html(data+'<?php 
            echo addslashes(img_info('Temps calculé sur base automatique avec un lancement immédiat. Ne peut être qu\'indicatif. Non contractuel'));
            ?>
');
					});
					
				}
				
			</script>
			
			</td>
			</tr>
			<?php 
        } else {
            if (in_array('projectcard', explode(':', $parameters['context']))) {
                if ($object->id > 0) {
                    ?>
				<tr>
					<td>Fin de production prévisionnelle</td>
					<td rel="date_fin_prod">
				<?php 
                    $res = $db->query("SELECT MAX(date_estimated_end) as date_estimated_end \n\t\t\t\t\tFROM " . MAIN_DB_PREFIX . "projet_task t \n\t\t\t\t\tLEFT JOIN " . MAIN_DB_PREFIX . "projet_task_extrafields tex ON (tex.fk_object=t.rowid)\n\t\t\t\t\t\tWHERE t.fk_projet = " . $object->id);
                    if ($obj = $db->fetch_object($res)) {
                        $t = strtotime($obj->date_estimated_end);
                        if ($t != '-62169987208') {
                            print dol_print_date($t, 'day') . img_info('Temps actuel présent dans l\'ordonnancement. Attention, peut-être revu à tout moment');
                        } else {
                            print 'Pas de tâche ordonnancée';
                        }
                    } else {
                        print 'Pas de tâche ordonnancée';
                    }
                    ?>
				</td></tr>
				<?php 
                }
            } else {
                if (in_array('actioncard', explode(':', $parameters['context']))) {
                    $fk_task = 0;
                    if ($action != 'create') {
                        $object->fetchObjectLinked();
                        //var_dump($object->linkedObjectsIds['task']);
                        if (!empty($object->linkedObjectsIds['task'])) {
                            list($key, $fk_task) = each($object->linkedObjectsIds['task']);
                        }
                    }
                    if ($action == 'edit' || $action == 'create') {
                        ?>
				<script type="text/javascript">
					$('#projectid').after('<span rel="fk_task"></span>');
				
					$('#projectid').change(function() {
						
						var fk_project = $(this).val();
						
						$.ajax({
							url:"<?php 
                        echo dol_buildpath('/scrumboard/script/interface.php', 1);
                        ?>
"
							,data: {
								get:"select-task"
								,fk_task:<?php 
                        echo $fk_task;
                        ?>
								,fk_project : fk_project
							}
								
						}).done(function(data) {
							$('span[rel=fk_task]').html(data);	
						});
						
						
						
						
					});
					$('#projectid').change();
				</script>	
				<?php 
                    } else {
                        dol_include_once('/projet/class/task.class.php');
                        $task = new Task($db);
                        $task->fetch($fk_task);
                        if (!empty($task->id)) {
                            ?>
				<tr>
					<td><?php 
                            echo $langs->trans('Task');
                            ?>
</td>
					<td rel="fk_task">
					<?php 
                            echo $task->getNomUrl(1) . ' ' . $task->label;
                            ?>
					</td>
				</tr>
				<?php 
                        }
                    }
                }
            }
        }
        return 0;
    }
function _tasks_ordo(&$db, &$TWorkstation, $status, $fk_workstation = 0)
{
    global $conf;
    $sql = "SELECT t.rowid,t.label,t.ref,t.fk_task_parent,t.fk_projet, t.grid_col,t.grid_row,ex.fk_workstation,ex.needed_ressource\n                ,t.planned_workload,t.progress,t.datee,t.dateo,p.fk_soc,t.date_estimated_end";
    if (!empty($conf->asset->enabled)) {
        $sql .= ',ex.fk_product';
    }
    // SCRUM_GROUP_TASK_BY_RAL est la conf qui crée les 2 extrafields au dessous
    if (!empty($conf->global->SCRUM_GROUP_TASK_BY_RAL)) {
        $sql .= ",ex.fk_product_ral";
    }
    $sql .= " FROM " . MAIN_DB_PREFIX . "projet_task t \n        LEFT JOIN " . MAIN_DB_PREFIX . "projet p ON (t.fk_projet=p.rowid)\n        LEFT JOIN " . MAIN_DB_PREFIX . "projet_task_extrafields ex ON (t.rowid=ex.fk_object) ";
    if ($status == 'ideas') {
        $sql .= " WHERE t.progress=0 AND t.datee IS NULL";
    } else {
        if ($status == 'todo') {
            $sql .= " WHERE t.progress=0";
        } else {
            if ($status == 'inprogress|todo') {
                $sql .= " WHERE t.progress>=0 AND t.progress<100 AND t.planned_workload>0";
            } else {
                if ($status == 'inprogress') {
                    $sql .= " WHERE t.progress>0 AND t.progress<100";
                } else {
                    if ($status == 'finish') {
                        $sql .= " WHERE t.progress=100\n        ";
                    }
                }
            }
        }
    }
    $sql .= " AND p.fk_statut IN (0,1)";
    if ($fk_workstation > 0) {
        $sql .= " AND ex.fk_workstation=" . (int) $fk_workstation;
    }
    if (empty($conf->global->SCRUM_ALLOW_ALL_TASK_IN_GRID)) {
        $sql .= " AND ex.grid_use=1 ";
    }
    $sql .= " ORDER BY t.grid_row, t.grid_col ";
    $res = $db->query($sql);
    $TTask = array();
    while ($obj = $db->fetch_object($res)) {
        $fk_workstation = (int) $obj->fk_workstation;
        if (!isset($TWorkstation[$fk_workstation])) {
            continue;
        }
        $workstation = $TWorkstation[$fk_workstation];
        $TUser = array();
        if (!empty($workstation['TUser'])) {
            foreach ($workstation['TUser'] as $idUser => $user) {
                $TUser[$idUser] = array('name' => $user->firstname . ' ' . $user->lastname, 'selected' => 0);
            }
            $task = new Task($db);
            $task->fetch($obj->rowid);
            $TIdContact = $task->getListContactId('internal');
            foreach ($TIdContact as $idContact) {
                $TUser[$idContact]['selected'] = 1;
            }
        }
        $TTask[] = array('status' => $status, 'id' => $obj->rowid, 'fk_projet' => $obj->fk_projet, 'label' => $obj->label, 'ref' => $obj->ref, 'grid_col' => $obj->grid_col, 'grid_row' => $obj->grid_row, 'fk_workstation' => $fk_workstation, 'fk_product' => (int) $obj->fk_product, 'fk_product_ral' => empty($conf->global->SCRUM_GROUP_TASK_BY_RAL) ? 0 : (int) $obj->fk_product_ral, 'fk_task_parent' => (int) $obj->fk_task_parent, 'needed_ressource' => $obj->needed_ressource ? $obj->needed_ressource : 1, 'planned_workload' => $obj->planned_workload / 3600, 'progress' => $obj->progress, 'fk_soc' => $obj->fk_soc, 'TUser' => $TUser, 'date_start' => strtotime($obj->dateo), 'date_end' => strtotime($obj->datee), 'date_estimated_end' => strtotime($obj->date_estimated_end));
    }
    return $TTask;
}
Example #16
0
if ($user->societe_id > 0) $socid = $user->societe_id;
//$result = restrictedArea($user, 'projet', $id, 'projet_task');
if (! $user->rights->projet->lire) accessforbidden();

$object = new Task($db);
$projectstatic = new Project($db);


/*
 * Actions
 */

// Add new contact
if ($action == 'addcontact' && $user->rights->projet->creer)
{
	$result = $object->fetch($id);

    if ($result > 0 && $id > 0)
    {
  		$result = $object->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
    }

	if ($result >= 0)
	{
		Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id.($withproject?'&withproject=1':''));
		exit;
	}
	else
	{
		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
		{
Example #17
0
 * @version 0.1
 * @date 2011-08-04  
 */
$GLOBALS['cfg_full_path'] = "../../";
include_once $GLOBALS['cfg_full_path'] . "config.php";
require_once 'callib/iCalcreator.class.php';
$c = new vcalendar(array('unique_id' => 'ofuz.net'));
$c->setProperty("method", "PUBLISH");
// required of some calendar software
$c->setProperty("x-wr-calname", "Ofuz Task");
// required of some calendar software
$c->setProperty("X-WR-CALDESC", "Ofuz Task Description");
// required of some calendar software
$v = new Task();
$apikey = $_REQUEST['apikey'];
$iduser = $v->getUserid($apikey);
if ($iduser != '') {
    $v->getAllTaskByuser($iduser);
    while ($v->fetch()) {
        $stdt = explode('-', $v->getData("due_date_dateformat"));
        $startdate = "{$stdt['0']}" . "{$stdt['1']}" . "{$stdt['2']}";
        $enddate = $startdate;
        $e =& $c->newComponent('vevent');
        $e->setProperty("dtstart", "{$startdate}", array("VALUE" => "DATE"));
        $e->setProperty('description', $v->getData("task_description"));
        $e->setProperty('summary', $v->getData("task_description"));
        $e->setProperty('class', 'PUBLIC');
    }
    $str = $c->createCalendar();
    echo $str;
}
Example #18
0
	$error=0;

	if (empty($_POST["timespent_durationhour"]) && empty($_POST["timespent_durationmin"]))
	{
		$mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Duration")).'</div>';
		$error++;
	}
	if (empty($_POST["userid"]))
	{
		$mesg='<div class="error">'.$langs->trans('ErrorUserNotAffectedToTask').'</div>';
		$error++;
	}

	if (! $error)
	{
		$object->fetch($id);

		$object->timespent_note = $_POST["timespent_note"];
		$object->timespent_duration = $_POST["timespent_durationhour"]*60*60;	// We store duration in seconds
		$object->timespent_duration+= $_POST["timespent_durationmin"]*60;		// We store duration in seconds
		$object->timespent_date = dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]);
		$object->timespent_fk_user = $_POST["userid"];

		$result=$object->addTimeSpent($user);
		if ($result >= 0)
		{

		}
		else
		{
			$mesg='<div class="error">'.$langs->trans($object->error).'</div>';
Example #19
0
$html = new Form($db);
$project = new Project($db);

$id = $_GET['id'];
$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{
	if ($mesg) print $mesg;

	$now=gmmktime();

	$task = new Task($db);
	$projectstatic = new Project($db);
	$userstatic = new User($db);

	if ($task->fetch($id, $ref))
	{
		$result=$projectstatic->fetch($task->fk_project);
		if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);

		// To verify role of users
		//$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
		//$arrayofuseridoftask=$task->getListContactId('internal');

		$head = task_prepare_head($task);
		dol_fiche_head($head, 'note', $langs->trans('Task'), 0, 'projecttask');

		print '<table class="border" width="100%">';

		//$linkback="<a href=\"".$_SERVER["PHP_SELF"]."?page=$page&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder\">".$langs->trans("BackToList")."</a>";
Example #20
0
    if ($year && $month && $day) {
        $daytoparse = dol_mktime(0, 0, 0, $month, $day, $year);
    }
}
// this are value submited after submit of action 'submitdateselect'
$object = new Task($db);
/*
 * Actions
 */
if (GETPOST('submitdateselect')) {
    $daytoparse = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
    $action = '';
}
if ($action == 'assign') {
    if ($taskid > 0) {
        $result = $object->fetch($taskid, $ref);
        if ($result < 0) {
            $error++;
        }
    } else {
        setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Task")), '', 'errors');
        $error++;
    }
    if (!GETPOST('type')) {
        setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), '', 'errors');
        $error++;
    }
    if (!$error) {
        $idfortaskuser = $user->id;
        $result = $object->add_contact($idfortaskuser, GETPOST("type"), 'internal');
        if ($result >= 0 || $result == -2) {
Example #21
0
}
if (!$sortfield) {
    $sortfield = "name";
}
$object = new Task($db);
$projectstatic = new Project($db);
/*
 * Actions
 */
// Retreive First Task ID of Project if withprojet is on to allow project prev next to work
if (!empty($project_ref) && !empty($withproject)) {
    if ($projectstatic->fetch(0, $project_ref) > 0) {
        $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
        if (count($tasksarray) > 0) {
            $id = $tasksarray[0]->id;
            $object->fetch($id);
        } else {
            header("Location: " . DOL_URL_ROOT . '/projet/tasks.php?id=' . $projectstatic->id . ($withproject ? '&withproject=1' : '') . (empty($mode) ? '' : '&mode=' . $mode));
            exit;
        }
    }
}
if ($id > 0 || !empty($ref)) {
    if ($object->fetch($id, $ref) > 0) {
        $projectstatic->fetch($object->fk_project);
        if (!empty($projectstatic->socid)) {
            $projectstatic->fetch_thirdparty();
        }
        $object->project = dol_clone($projectstatic);
        $upload_dir = $conf->projet->dir_output . '/' . dol_sanitizeFileName($projectstatic->ref) . '/' . dol_sanitizeFileName($object->ref);
    } else {
 function set_project_task(&$PDOdb, $progress)
 {
     global $db;
     require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php';
     $projectTask = new Task($db);
     $projectTask->fetch($this->fk_project_task);
     $projectTask->progress = $progress;
     $projectTask->update($db);
 }
 /**
  *	Function to build a document on disk using the generic odt module.
  *
  *	@param	Project		$object					Object source to build document
  *	@param	Translate	$outputlangs			Lang output object
  * 	@param	string		$srctemplatepath	    Full path of source filename for generator using a template file
  *	@return	int         						1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs, $srctemplatepath)
 {
     global $user, $langs, $conf, $mysoc, $hookmanager;
     if (empty($srctemplatepath)) {
         dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
         return -1;
     }
     // Add odtgeneration hook
     if (!is_object($hookmanager)) {
         include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
         $hookmanager = new HookManager($this->db);
     }
     $hookmanager->initHooks(array('odtgeneration'));
     global $action;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     $sav_charset_output = $outputlangs->charset_output;
     $outputlangs->charset_output = 'UTF-8';
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("projects");
     if ($conf->projet->dir_output) {
         // If $object is id instead of object
         if (!is_object($object)) {
             $id = $object;
             $object = new Project($this->db);
             $result = $object->fetch($id);
             if ($result < 0) {
                 dol_print_error($this->db, $object->error);
                 return -1;
             }
         }
         $dir = $conf->projet->dir_output;
         $objectref = dol_sanitizeFileName($object->ref);
         if (!preg_match('/specimen/i', $objectref)) {
             $dir .= "/" . $objectref;
         }
         $file = $dir . "/" . $objectref . ".odt";
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return -1;
             }
         }
         if (file_exists($dir)) {
             //print "srctemplatepath=".$srctemplatepath;	// Src filename
             $newfile = basename($srctemplatepath);
             $newfiletmp = preg_replace('/\\.od(t|s)/i', '', $newfile);
             $newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
             $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
             $newfiletmp = $objectref . '_' . $newfiletmp;
             //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
             // Get extension (ods or odt)
             $newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
             if (!empty($conf->global->MAIN_DOC_USE_TIMING)) {
                 $filename = $newfiletmp . '.' . dol_print_date(dol_now(), '%Y%m%d%H%M%S') . '.' . $newfileformat;
             } else {
                 $filename = $newfiletmp . '.' . $newfileformat;
             }
             $file = $dir . '/' . $filename;
             //print "newdir=".$dir;
             //print "newfile=".$newfile;
             //print "file=".$file;
             //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
             dol_mkdir($conf->projet->dir_temp);
             $socobject = $object->thirdparty;
             // Make substitution
             $substitutionarray = array('__FROM_NAME__' => $this->emetteur->nom, '__FROM_EMAIL__' => $this->emetteur->email);
             complete_substitutions_array($substitutionarray, $langs, $object);
             // Open and load template
             require_once ODTPHP_PATH . 'odf.php';
             try {
                 $odfHandler = new odf($srctemplatepath, array('PATH_TO_TMP' => $conf->projet->dir_temp, 'ZIP_PROXY' => 'PclZipProxy', 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}'));
             } catch (Exception $e) {
                 $this->error = $e->getMessage();
                 return -1;
             }
             // After construction $odfHandler->contentXml contains content and
             // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
             // [!-- BEGIN lines --]*[!-- END lines --]
             //print html_entity_decode($odfHandler->__toString());
             //print exit;
             // Make substitutions into odt of user info
             $tmparray = $this->get_substitutionarray_user($user, $outputlangs);
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         //var_dump($value);exit;
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Make substitutions into odt of mysoc
             $tmparray = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
             //var_dump($tmparray); exit;
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         //var_dump($value);exit;
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Make substitutions into odt of thirdparty
             $tmparray = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Replace tags of object + external modules
             $tmparray = $this->get_substitutionarray_object($object, $outputlangs);
             complete_substitutions_array($tmparray, $outputlangs, $object);
             // Call the ODTSubstitution hook
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
             $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Replace tags of lines for tasks
             try {
                 $listlines = $odfHandler->setSegment('tasks');
                 $taskstatic = new Task($this->db);
                 // Security check
                 $socid = 0;
                 if (!empty($object->fk_soc)) {
                     $socid = $object->fk_soc;
                 }
                 $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $socid, 0);
                 foreach ($tasksarray as $task) {
                     $tmparray = $this->get_substitutionarray_tasks($task, $outputlangs);
                     //complete_substitutions_array($tmparray, $outputlangs, $object, $task, "completesubstitutionarray_lines");
                     foreach ($tmparray as $key => $val) {
                         try {
                             $listlines->setVars($key, $val, true, 'UTF-8');
                         } catch (OdfException $e) {
                         } catch (SegmentException $e) {
                         }
                     }
                     $taskobj = new Task($this->db);
                     $taskobj->fetch($task->id);
                     // Replace tags of lines for contacts task
                     $sourcearray = array('internal', 'external');
                     $contact_arrray = array();
                     foreach ($sourcearray as $source) {
                         $contact_temp = $taskobj->liste_contact(-1, $source);
                         if (is_array($contact_temp) && count($contact_temp) > 0) {
                             $contact_arrray = array_merge($contact_arrray, $contact_temp);
                         }
                     }
                     if (is_array($contact_arrray) && count($contact_arrray) > 0) {
                         $listlinestaskres = $listlines->__get('tasksressources');
                         foreach ($contact_arrray as $contact) {
                             if ($contact['source'] == 'internal') {
                                 $objectdetail = new User($this->db);
                                 $objectdetail->fetch($contact['id']);
                                 $contact['socname'] = $mysoc->name;
                             } elseif ($contact['source'] == 'external') {
                                 $objectdetail = new Contact($this->db);
                                 $objectdetail->fetch($contact['id']);
                                 $soc = new Societe($this->db);
                                 $soc->fetch($contact['socid']);
                                 $contact['socname'] = $soc->name;
                             }
                             $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1);
                             $tmparray = $this->get_substitutionarray_tasksressource($contact, $outputlangs);
                             foreach ($tmparray as $key => $val) {
                                 try {
                                     $listlinestaskres->setVars($key, $val, true, 'UTF-8');
                                 } catch (OdfException $e) {
                                 } catch (SegmentException $e) {
                                 }
                             }
                             $listlinestaskres->merge();
                         }
                     }
                     //Time ressources
                     $sql = "SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note";
                     $sql .= ", u.lastname, u.firstname";
                     $sql .= " FROM " . MAIN_DB_PREFIX . "projet_task_time as t";
                     $sql .= " , " . MAIN_DB_PREFIX . "user as u";
                     $sql .= " WHERE t.fk_task =" . $task->id;
                     $sql .= " AND t.fk_user = u.rowid";
                     $sql .= " ORDER BY t.task_date DESC";
                     $resql = $this->db->query($sql);
                     if ($resql) {
                         $num = $this->db->num_rows($resql);
                         $i = 0;
                         $tasks = array();
                         $listlinestasktime = $listlines->__get('taskstimes');
                         while ($i < $num) {
                             $row = $this->db->fetch_array($resql);
                             if (!empty($row['fk_user'])) {
                                 $objectdetail = new User($this->db);
                                 $objectdetail->fetch($row['fk_user']);
                                 $row['fullcivname'] = $objectdetail->getFullName($outputlangs, 1);
                             } else {
                                 $row['fullcivname'] = '';
                             }
                             $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs);
                             foreach ($tmparray as $key => $val) {
                                 try {
                                     $listlinestasktime->setVars($key, $val, true, 'UTF-8');
                                 } catch (OdfException $e) {
                                 } catch (SegmentException $e) {
                                 }
                             }
                             $listlinestasktime->merge();
                             $i++;
                         }
                         $this->db->free($resql);
                     }
                     // Replace tags of project files
                     $listtasksfiles = $listlines->__get('tasksfiles');
                     $upload_dir = $conf->projet->dir_output . '/' . dol_sanitizeFileName($object->ref) . '/' . dol_sanitizeFileName($task->ref);
                     $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', 'name', SORT_ASC, 1);
                     foreach ($filearray as $filedetail) {
                         $tmparray = $this->get_substitutionarray_task_file($filedetail, $outputlangs);
                         //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true));
                         foreach ($tmparray as $key => $val) {
                             try {
                                 $listtasksfiles->setVars($key, $val, true, 'UTF-8');
                             } catch (OdfException $e) {
                             } catch (SegmentException $e) {
                             }
                         }
                         $listtasksfiles->merge();
                     }
                     $listlines->merge();
                 }
                 $odfHandler->mergeSegment($listlines);
             } catch (OdfException $e) {
                 $this->error = $e->getMessage();
                 dol_syslog($this->error, LOG_WARNING);
                 return -1;
             }
             // Replace tags of project files
             try {
                 $listlines = $odfHandler->setSegment('projectfiles');
                 $upload_dir = $conf->projet->dir_output . '/' . dol_sanitizeFileName($object->ref);
                 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', 'name', SORT_ASC, 1);
                 foreach ($filearray as $filedetail) {
                     //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true));
                     $tmparray = $this->get_substitutionarray_project_file($filedetail, $outputlangs);
                     foreach ($tmparray as $key => $val) {
                         try {
                             $listlines->setVars($key, $val, true, 'UTF-8');
                         } catch (OdfException $e) {
                         } catch (SegmentException $e) {
                         }
                     }
                     $listlines->merge();
                 }
                 $odfHandler->mergeSegment($listlines);
             } catch (OdfException $e) {
                 $this->error = $e->getMessage();
                 dol_syslog($this->error, LOG_WARNING);
                 return -1;
             }
             // Replace tags of lines for contacts
             $sourcearray = array('internal', 'external');
             $contact_arrray = array();
             foreach ($sourcearray as $source) {
                 $contact_temp = $object->liste_contact(-1, $source);
                 if (is_array($contact_temp) && count($contact_temp) > 0) {
                     $contact_arrray = array_merge($contact_arrray, $contact_temp);
                 }
             }
             if (is_array($contact_arrray) && count($contact_arrray) > 0) {
                 try {
                     $listlines = $odfHandler->setSegment('projectcontacts');
                     foreach ($contact_arrray as $contact) {
                         if ($contact['source'] == 'internal') {
                             $objectdetail = new User($this->db);
                             $objectdetail->fetch($contact['id']);
                             $contact['socname'] = $mysoc->name;
                         } elseif ($contact['source'] == 'external') {
                             $objectdetail = new Contact($this->db);
                             $objectdetail->fetch($contact['id']);
                             $soc = new Societe($this->db);
                             $soc->fetch($contact['socid']);
                             $contact['socname'] = $soc->name;
                         }
                         $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1);
                         $tmparray = $this->get_substitutionarray_project_contacts($contact, $outputlangs);
                         foreach ($tmparray as $key => $val) {
                             try {
                                 $listlines->setVars($key, $val, true, 'UTF-8');
                             } catch (OdfException $e) {
                             } catch (SegmentException $e) {
                             }
                         }
                         $listlines->merge();
                     }
                     $odfHandler->mergeSegment($listlines);
                 } catch (OdfException $e) {
                     $this->error = $e->getMessage();
                     dol_syslog($this->error, LOG_WARNING);
                     return -1;
                 }
             }
             //List of referent
             $listofreferent = array('propal' => array('title' => "ListProposalsAssociatedProject", 'class' => 'Propal', 'table' => 'propal', 'test' => $conf->propal->enabled && $user->rights->propale->lire), 'order' => array('title' => "ListOrdersAssociatedProject", 'class' => 'Commande', 'table' => 'commande', 'test' => $conf->commande->enabled && $user->rights->commande->lire), 'invoice' => array('title' => "ListInvoicesAssociatedProject", 'class' => 'Facture', 'table' => 'facture', 'test' => $conf->facture->enabled && $user->rights->facture->lire), 'invoice_predefined' => array('title' => "ListPredefinedInvoicesAssociatedProject", 'class' => 'FactureRec', 'table' => 'facture_rec', 'test' => $conf->facture->enabled && $user->rights->facture->lire), 'order_supplier' => array('title' => "ListSupplierOrdersAssociatedProject", 'table' => 'commande_fournisseur', 'class' => 'CommandeFournisseur', 'test' => $conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire), 'invoice_supplier' => array('title' => "ListSupplierInvoicesAssociatedProject", 'table' => 'facture_fourn', 'class' => 'FactureFournisseur', 'test' => $conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), 'contract' => array('title' => "ListContractAssociatedProject", 'class' => 'Contrat', 'table' => 'contrat', 'test' => $conf->contrat->enabled && $user->rights->contrat->lire), 'intervention' => array('title' => "ListFichinterAssociatedProject", 'class' => 'Fichinter', 'table' => 'fichinter', 'disableamount' => 1, 'test' => $conf->ficheinter->enabled && $user->rights->ficheinter->lire), 'trip' => array('title' => "ListTripAssociatedProject", 'class' => 'Deplacement', 'table' => 'deplacement', 'disableamount' => 1, 'test' => $conf->deplacement->enabled && $user->rights->deplacement->lire), 'agenda' => array('title' => "ListActionsAssociatedProject", 'class' => 'ActionComm', 'table' => 'actioncomm', 'disableamount' => 1, 'test' => $conf->agenda->enabled && $user->rights->agenda->allactions->lire));
             //Insert reference
             try {
                 $listlines = $odfHandler->setSegment('projectrefs');
                 foreach ($listofreferent as $keyref => $valueref) {
                     $title = $valueref['title'];
                     $tablename = $valueref['table'];
                     $classname = $valueref['class'];
                     $qualified = $valueref['test'];
                     if ($qualified) {
                         $elementarray = $object->get_element_list($keyref, $tablename);
                         if (count($elementarray) > 0 && is_array($elementarray)) {
                             $var = true;
                             $total_ht = 0;
                             $total_ttc = 0;
                             $num = count($elementarray);
                             for ($i = 0; $i < $num; $i++) {
                                 $ref_array = array();
                                 $ref_array['type'] = $langs->trans($classname);
                                 $element = new $classname($this->db);
                                 $element->fetch($elementarray[$i]);
                                 $element->fetch_thirdparty();
                                 //Ref object
                                 $ref_array['ref'] = $element->ref;
                                 //Date object
                                 $dateref = $element->date;
                                 if (empty($dateref)) {
                                     $dateref = $element->datep;
                                 }
                                 if (empty($dateref)) {
                                     $dateref = $element->date_contrat;
                                 }
                                 $ref_array['date'] = $dateref;
                                 //Soc object
                                 if (is_object($element->thirdparty)) {
                                     $ref_array['socname'] = $element->thirdparty->name;
                                 } else {
                                     $ref_array['socname'] = '';
                                 }
                                 //Amount object
                                 if (empty($valueref['disableamount'])) {
                                     if (!empty($element->total_ht)) {
                                         $ref_array['amountht'] = $element->total_ht;
                                         $ref_array['amountttc'] = $element->total_ttc;
                                     } else {
                                         $ref_array['amountht'] = 0;
                                         $ref_array['amountttc'] = 0;
                                     }
                                 } else {
                                     $ref_array['amountht'] = '';
                                     $ref_array['amountttc'] = '';
                                 }
                                 $ref_array['status'] = $element->getLibStatut(0);
                                 $tmparray = $this->get_substitutionarray_project_reference($ref_array, $outputlangs);
                                 foreach ($tmparray as $key => $val) {
                                     try {
                                         $listlines->setVars($key, $val, true, 'UTF-8');
                                     } catch (OdfException $e) {
                                     } catch (SegmentException $e) {
                                     }
                                 }
                                 $listlines->merge();
                             }
                         }
                     }
                     $odfHandler->mergeSegment($listlines);
                 }
             } catch (OdfException $e) {
                 $this->error = $e->getMessage();
                 dol_syslog($this->error, LOG_WARNING);
                 return -1;
             }
             // Replace labels translated
             $tmparray = $outputlangs->get_translations_for_substitutions();
             foreach ($tmparray as $key => $value) {
                 try {
                     $odfHandler->setVars($key, $value, true, 'UTF-8');
                 } catch (OdfException $e) {
                 }
             }
             // Call the beforeODTSave hook
             $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             // Write new file
             if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
                 try {
                     $odfHandler->exportAsAttachedPDF($file);
                 } catch (Exception $e) {
                     $this->error = $e->getMessage();
                     return -1;
                 }
             } else {
                 try {
                     $odfHandler->saveToDisk($file);
                 } catch (Exception $e) {
                     $this->error = $e->getMessage();
                     return -1;
                 }
             }
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             $odfHandler = null;
             // Destroy object
             return 1;
             // Success
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return -1;
         }
     }
     return -1;
 }
Example #24
0

if (count($tasksarray)>0)
{

	// Show Gant diagram from $taskarray using JSGantt

	$dateformat=$langs->trans("FormatDateShort");
	$dateformat=strtolower($langs->trans("FormatDateShortJava"));
	$array_contacts=array();
	$tasks=array();
	$project_dependencies=array();
	$taskcursor=0;
	foreach($tasksarray as $key => $val)
	{
		$task->fetch($val->id);
		$tasks[$taskcursor]['task_id']=$val->id;
		$tasks[$taskcursor]['task_parent']=$val->fk_parent;
		$tasks[$taskcursor]['task_is_group']=0;
		$tasks[$taskcursor]['task_milestone']=0;
		$tasks[$taskcursor]['task_percent_complete']=$val->progress;
		//$tasks[$taskcursor]['task_name']=$task->getNomUrl(1);
		$tasks[$taskcursor]['task_name']=$val->label;
		$tasks[$taskcursor]['task_start_date']=$val->date_start;
		$tasks[$taskcursor]['task_end_date']=$val->date_end;
		$tasks[$taskcursor]['task_color']='b4d1ea';
		$idofusers=$task->getListContactId('internal');
		$idofthirdparty=$task->getListContactId('external');
		$s='';
		if (count($idofusers)>0)
		{
 */
if ($action == 'addtimespent' && $user->rights->projet->creer) {
    $error = 0;
    $timespent_durationhour = GETPOST('timespent_durationhour', 'int');
    $timespent_durationmin = GETPOST('timespent_durationmin', 'int');
    if (empty($timespent_durationhour) && empty($timespent_durationmin)) {
        setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), 'errors');
        $error++;
    }
    if (empty($_POST["userid"])) {
        $langs->load("errors");
        setEventMessage($langs->trans('ErrorUserNotAssignedToTask'), 'errors');
        $error++;
    }
    if (!$error) {
        $object->fetch($id, $ref);
        $object->timespent_note = $_POST["timespent_note"];
        $object->timespent_duration = $_POST["timespent_durationhour"] * 60 * 60;
        // We store duration in seconds
        $object->timespent_duration += $_POST["timespent_durationmin"] * 60;
        // We store duration in seconds
        $object->timespent_date = dol_mktime(12, 0, 0, $_POST["timemonth"], $_POST["timeday"], $_POST["timeyear"]);
        $object->timespent_fk_user = $_POST["userid"];
        $result = $object->addTimeSpent($user);
        if ($result >= 0) {
            setEventMessage($langs->trans("RecordSaved"));
        } else {
            setEventMessage($langs->trans($object->error), 'errors');
            $error++;
        }
    } else {
Example #26
0
$socid = 0;
if ($user->societe_id > 0) {
    $socid = $user->societe_id;
}
//$result = restrictedArea($user, 'projet', $id, 'projet_task');
if (!$user->rights->projet->lire) {
    accessforbidden();
}
$object = new Task($db);
$projectstatic = new Project($db);
/*
 * Actions
 */
// Add new contact
if ($action == 'addcontact' && $user->rights->projet->creer) {
    $result = $object->fetch($id, $ref);
    if ($result > 0 && $id > 0) {
        $idfortaskuser = GETPOST("contactid") != 0 ? GETPOST("contactid") : GETPOST("userid");
        // GETPOST('contactid') may val -1 to mean empty or -2 to means "everybody"
        if ($idfortaskuser == -2) {
            $result = $projectstatic->fetch($object->fk_project);
            if ($result <= 0) {
                dol_print_error($db, $projectstatic->error, $projectstatic->errors);
            } else {
                $contactsofproject = $projectstatic->getListContactId('internal');
                foreach ($contactsofproject as $key => $val) {
                    $result = $object->add_contact($val, GETPOST("type"), GETPOST("source"));
                }
            }
        } else {
            $result = $object->add_contact($idfortaskuser, GETPOST("type"), GETPOST("source"));
Example #27
0
 /**	Load an object from its id and create a new one in database
  *
  *	@param	int		$fromid     			Id of object to clone
  *  @param	int		$project_id				Id of project to attach clone task
  *  @param	int		$parent_task_id			Id of task to attach clone task
  *  @param	bool	$clone_change_dt		recalculate date of task regarding new project start date
  *	@param	bool	$clone_affectation		clone affectation of project
  *	@param	bool	$clone_time				clone time of project
  *	@param	bool	$clone_file				clone file of project
  *  @param	bool	$clone_note				clone note of project
  *	@param	bool	$clone_prog				clone progress of project
  * 	@return	int								New id of clone
  */
 function createFromClone($fromid, $project_id, $parent_task_id, $clone_change_dt = false, $clone_affectation = false, $clone_time = false, $clone_file = false, $clone_note = false, $clone_prog = false)
 {
     global $user, $langs, $conf;
     $error = 0;
     //Use 00:00 of today if time is use on task.
     $now = dol_mktime(0, 0, 0, dol_print_date(dol_now(), '%m'), dol_print_date(dol_now(), '%d'), dol_print_date(dol_now(), '%Y'));
     $datec = $now;
     $clone_task = new Task($this->db);
     $origin_task = new Task($this->db);
     $clone_task->context['createfromclone'] = 'createfromclone';
     $this->db->begin();
     // Load source object
     $clone_task->fetch($fromid);
     $origin_task->fetch($fromid);
     $defaultref = '';
     $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
     if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . ".php")) {
         require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . '.php';
         $modTask = new $obj();
         $defaultref = $modTask->getNextValue(0, $clone_task);
     }
     $ori_project_id = $clone_task->fk_project;
     $clone_task->id = 0;
     $clone_task->ref = $defaultref;
     $clone_task->fk_project = $project_id;
     $clone_task->fk_task_parent = $parent_task_id;
     $clone_task->date_c = $datec;
     $clone_task->planned_workload = $origin_task->planned_workload;
     $clone_task->rang = $origin_task->rang;
     //Manage Task Date
     if ($clone_change_dt) {
         $projectstatic = new Project($this->db);
         $projectstatic->fetch($ori_project_id);
         //Origin project strat date
         $orign_project_dt_start = $projectstatic->date_start;
         //Calcultate new task start date with difference between origin proj start date and origin task start date
         if (!empty($clone_task->date_start)) {
             $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
         }
         //Calcultate new task end date with difference between origin proj end date and origin task end date
         if (!empty($clone_task->date_end)) {
             $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
         }
     }
     if (!$clone_prog) {
         $clone_task->progress = 0;
     }
     // Create clone
     $result = $clone_task->create($user);
     // Other options
     if ($result < 0) {
         $this->error = $clone_task->error;
         $error++;
     }
     // End
     if (!$error) {
         $clone_task_id = $clone_task->id;
         $clone_task_ref = $clone_task->ref;
         //Note Update
         if (!$clone_note) {
             $clone_task->note_private = '';
             $clone_task->note_public = '';
         } else {
             $this->db->begin();
             $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_public, ENT_QUOTES), '_public');
             if ($res < 0) {
                 $this->error .= $clone_task->error;
                 $error++;
                 $this->db->rollback();
             } else {
                 $this->db->commit();
             }
             $this->db->begin();
             $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_private, ENT_QUOTES), '_private');
             if ($res < 0) {
                 $this->error .= $clone_task->error;
                 $error++;
                 $this->db->rollback();
             } else {
                 $this->db->commit();
             }
         }
         //Duplicate file
         if ($clone_file) {
             require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
             //retreive project origin ref to know folder to copy
             $projectstatic = new Project($this->db);
             $projectstatic->fetch($ori_project_id);
             $ori_project_ref = $projectstatic->ref;
             if ($ori_project_id != $project_id) {
                 $projectstatic->fetch($project_id);
                 $clone_project_ref = $projectstatic->ref;
             } else {
                 $clone_project_ref = $ori_project_ref;
             }
             $clone_task_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($clone_project_ref) . "/" . dol_sanitizeFileName($clone_task_ref);
             $ori_task_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($ori_project_ref) . "/" . dol_sanitizeFileName($fromid);
             $filearray = dol_dir_list($ori_task_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', '', SORT_ASC, 1);
             foreach ($filearray as $key => $file) {
                 if (!file_exists($clone_task_dir)) {
                     if (dol_mkdir($clone_task_dir) < 0) {
                         $this->error .= $langs->trans('ErrorInternalErrorDetected') . ':dol_mkdir';
                         $error++;
                     }
                 }
                 $rescopy = dol_copy($ori_task_dir . '/' . $file['name'], $clone_task_dir . '/' . $file['name'], 0, 1);
                 if (is_numeric($rescopy) && $rescopy < 0) {
                     $this->error .= $langs->trans("ErrorFailToCopyFile", $ori_task_dir . '/' . $file['name'], $clone_task_dir . '/' . $file['name']);
                     $error++;
                 }
             }
         }
         // clone affectation
         if ($clone_affectation) {
             $origin_task = new Task($this->db);
             $origin_task->fetch($fromid);
             foreach (array('internal', 'external') as $source) {
                 $tab = $origin_task->liste_contact(-1, $source);
                 $num = count($tab);
                 $i = 0;
                 while ($i < $num) {
                     $clone_task->add_contact($tab[$i]['id'], $tab[$i]['code'], $tab[$i]['source']);
                     if ($clone_task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
                         $langs->load("errors");
                         $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
                         $error++;
                     } else {
                         if ($clone_task->error != '') {
                             $this->error .= $clone_task->error;
                             $error++;
                         }
                     }
                     $i++;
                 }
             }
         }
         if ($clone_time) {
             //TODO clone time of affectation
         }
     }
     unset($clone_task->context['createfromclone']);
     if (!$error) {
         $this->db->commit();
         return $clone_task_id;
     } else {
         $this->db->rollback();
         dol_syslog(get_class($this) . "::createFromClone nbError: " . $error . " error : " . $this->error, LOG_ERR);
         return -1;
     }
 }
function getTaskFromProjet($idProjet)
{
    global $db;
    $TTask == array();
    $sql = "SELECT rowid ";
    $sql .= "FROM " . MAIN_DB_PREFIX . "projet_task ";
    $sql .= "WHERE fk_projet=" . $idProjet;
    $resql = $db->query($sql);
    if ($resql) {
        while ($line = $db->fetch_object($resql)) {
            $task = new Task($db);
            $task->fetch($line->rowid);
            //TODO ajouter cette putain de tache au tableau TTaches
            $TTask[] = $task;
        }
    }
    return $TTask;
}