Esempio n. 1
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;

		$now=dol_now();

		$datec = $now;

		$clone_task=new Task($this->db);

		$this->db->begin();

		// Load source object
		$clone_task->fetch($fromid);

		$ori_project_id					= $clone_task->fk_project;

		$clone_task->id					= 0;
        $clone_task->fk_project			= $project_id;
        $clone_task->fk_task_parent		= $parent_task_id;
        $clone_task->date_c				= $datec;

        //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)
		{
			$this->db->commit();

			$clone_task_id=$clone_task->id;

       		//Note Update
			if (!$clone_note)
       		{
        	    $clone_task->note_private='';
    			$clone_task->note_public='';
        	}
        	else
        	{
        		$this->db->begin();
				$res=$clone_task->update_note_public(dol_html_entity_decode($clone_task->note_public, ENT_QUOTES));
				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));
				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_id);
				$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$','',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
			}

			if (! $error)
			{
				return $clone_task_id;
			}
			else
			{
				dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
				return -1;
			}
		}
		else
		{
			$this->db->rollback();
			return -1;
		}
	}
Esempio n. 2
0
 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) {
         // Test if we are already contact of the project (should be rare but sometimes we can add as task contact without being contact of project, like when admin user has been removed from contact of project)
         $sql = 'SELECT ec.rowid FROM ' . MAIN_DB_PREFIX . 'element_contact as ec, ' . MAIN_DB_PREFIX . 'c_type_contact as tc WHERE tc.rowid = ec.fk_c_type_contact';
         $sql .= ' AND ec.fk_socpeople = ' . $idfortaskuser . " AND ec.element_id = '.{$object->fk_project}.' AND tc.element = 'project' AND source = 'internal'";
         $resql = $db->query($sql);
         if ($resql) {
             $obj = $db->fetch_object($resql);
             if (!$obj) {
                 $project = new Project($db);
                 $project->fetch($object->fk_project);
                 // Get type
                 $listofprojcontact = $project->liste_type_contact('internal');
                 if (count($listofprojcontact)) {
                     $typeforprojectcontact = reset(array_keys($listofprojcontact));
                     $result = $project->add_contact($idfortaskuser, $typeforprojectcontact, 'internal');
Esempio n. 3
0
 * 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"));
        }
    }
    if ($result >= 0) {
        header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $object->id . ($withproject ? '&withproject=1' : ''));
        exit;
    } else {
        if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
            $langs->load("errors");
            setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
        } else {
            setEventMessage($object->error, 'errors');
Esempio n. 4
0
			$task = new Task($db);

			$task->fk_project = $projectid;
			$task->label = $_POST["label"];
			$task->description = $_POST['description'];
			$task->fk_task_parent = $task_parent;
			$task->date_c = dol_now();
			$task->date_start = $date_start;
			$task->date_end = $date_end;
			$task->progress = $_POST['progress'];

			$taskid = $task->create($user);

			if ($taskid > 0)
			{
				$result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
			}
		}

		if (! $error)
		{
			if (empty($projectid))
			{
				Header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($_REQUEST["mode"])?'':'?mode='.$_REQUEST["mode"]));
				exit;
			}
			else
			{
				Header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$taskid);
				exit;
			}
function _set_user_in_task($taskid, $userid)
{
    global $db;
    $task = new Task($db);
    $task->fetch($taskid);
    return $task->add_contact($userid, 180, 'internal');
}
Esempio n. 6
0
$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')
		{
			$langs->load("errors");
			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
		}
		else
Esempio n. 7
0
/*
 * Actions
 */

// Add new contact
if ($_POST["action"] == 'addcontact' && $user->rights->projet->creer)
{

	$result = 0;
	$task = new Task($db);
	$result = $task->fetch($taskid);

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

	if ($result >= 0)
	{
		Header("Location: contact.php?id=".$task->id);
		exit;
	}
	else
	{
		if ($task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
		{
			$langs->load("errors");
			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
		}
		else