/**
  *	Output a combo list with projects qualified for a third party
  *
  *	@param	int		$socid      	Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id)
  *	@param  int		$selected   	Id project preselected
  *	@param  string	$htmlname   	Nom de la zone html
  *	@param	int		$maxlength		Maximum length of label
  *	@param	int		$option_only	Return only html options lines without the select tag
  *	@param	int		$show_empty		Add an empty line
  *  @param	int		$discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable)
  *  @param	int		$forcefocus		Force focus on field (works with javascript only)
  *  @param	int		$disabled		Disabled
  *  @param  int     $mode           0 for HTML mode and 1 for JSON mode
  *  @param  string  $filterkey      Key to filter
  *	@return int         			Nber of project if OK, <0 if KO
  */
 function select_projects($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 16, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '')
 {
     global $langs, $conf, $form;
     if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT)) {
         $placeholder = '';
         if ($selected && empty($selected_input_value)) {
             require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
             $project = new Project($this->db);
             $project->fetch($selected);
             $selected_input_value = $project->ref;
         }
         $urloption = 'socid=' . $socid . '&htmlname=' . $htmlname;
         print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array());
         print '<input type="text" size="20" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />';
     } else {
         print $this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey);
         if ($discard_closed) {
             if (class_exists('Form')) {
                 if (empty($form)) {
                     $form = new Form($this->db);
                 }
                 print $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
             }
         }
     }
 }
예제 #2
0
 protected function handleRequest(array $request)
 {
     $projectId = $request[self::FIELD_PROJECT_ID];
     $project = Project::fetch($projectId);
     // FIXME: global::lock()
     Project::erase($projectId);
     Project::shiftLeft($project->getOrd());
 }
예제 #3
0
 protected function handleRequest(array $request)
 {
     $projectId = $request[self::FIELD_PROJECT_ID];
     $project = Project::fetch($projectId);
     $lists = TasksList::fetchAllInProject($projectId);
     $listsRep = array();
     foreach ($lists as $list) {
         $tasks = Task::fetchAllInList($list->getId());
         $tasksRep = array();
         foreach ($tasks as $task) {
             $tasksRep[] = array(self::FIELD_TITLE => $task->getTitle(), self::FIELD_DESCRIPTION => $task->getDescription(), self::FIELD_TASK_STATUS => $task->getStatus());
         }
         $listsRep[] = array(self::FIELD_TITLE => $list->getTitle(), self::FIELD_TASKS => $tasksRep);
     }
     return array(self::FIELD_PROTOCOL_VERSION => self::CURRENT_PROTOCOL_VERSION, self::FIELD_TITLE => $project->getTitle(), self::FIELD_DESCRIPTION => $project->getDescription(), self::FIELD_LISTS => $listsRep);
 }
예제 #4
0
 protected function handleRequest(array $request)
 {
     $beforeId = $request[self::FIELD_BEFORE_PROJECT_ID];
     $title = $request[self::FIELD_TITLE];
     $description = $request[self::FIELD_DESCRIPTION];
     // FIXME: Global::lock();
     $ord = null;
     if ($beforeId) {
         $beforeProject = Project::fetch($beforeId);
         $ord = $beforeProject->getOrd();
         Project::shiftRight($ord);
     } else {
         $ord = Project::getNextOrd();
     }
     $projectId = Project::create($ord, $title, $description);
     return array(self::FIELD_PROJECT_ID => $projectId);
 }
예제 #5
0
 protected function handleRequest(array $request)
 {
     $projectId = $request[self::FIELD_PROJECT_ID];
     $beforeProjectId = $request[self::FIELD_BEFORE_PROJECT_ID];
     $project = Project::fetch($projectId);
     // FIXME: Global::lock();
     if ($beforeProjectId) {
         Project::shiftLeft($project->getOrd());
         if ($beforeProjectId === $projectId) {
             throw new Exception("Can't move project before itself", EndPoint::STATUS_BAD_REQUEST);
         }
         $beforeProject = Project::fetch($beforeProjectId);
         Project::shiftRight($beforeProject->getOrd());
         Project::updateOrd($projectId, $beforeProject->getOrd());
     } else {
         Project::shiftLeft($project->getOrd());
         Project::updateOrd($projectId, Project::getNextOrd());
     }
 }
예제 #6
0
 protected function handleRequest(array $request)
 {
     $projectId = $request[self::FIELD_PROJECT_ID];
     $excludeClosedTasks = $request[self::FIELD_EXCLUDE_CLOSED_TASKS];
     $project = Project::fetch($projectId);
     $lists = TasksList::fetchAllInProject($projectId);
     $listsRep = array();
     foreach ($lists as $list) {
         $tasks = Task::fetchAllInList($list->getId());
         $tasksRep = array();
         foreach ($tasks as $task) {
             if ($excludeClosedTasks && $task->getStatus() == Task::STATUS_CLOSED) {
                 continue;
             }
             $tasksRep[] = array(self::FIELD_TASK_ID => $task->getId(), self::FIELD_TITLE => $task->getTitle(), self::FIELD_DESCRIPTION => $task->getDescription(), self::FIELD_TASK_STATUS => $task->getStatus());
         }
         $listsRep[] = array(self::FIELD_LIST_ID => $list->getId(), self::FIELD_TITLE => $list->getTitle(), self::FIELD_TASKS => $tasksRep);
     }
     return array(self::FIELD_PROJECT_ID => $project->getId(), self::FIELD_TITLE => $project->getTitle(), self::FIELD_DESCRIPTION => $project->getDescription(), self::FIELD_LISTS => $listsRep);
 }
function scrum_getVelocity(&$db, $id_project)
{
    global $conf;
    $n_day = $conf->global->SCRUM_VELOCITY_NUMBER_OF_DAY ? $conf->global->SCRUM_VELOCITY_NUMBER_OF_DAY : 14;
    $t2week = strtotime('-' . $n_day . ' days');
    $projet = new Project($db);
    $projet->fetch($id_project);
    if ($projet->date_start > $t2week) {
        $t2week = $projet->date_start;
    }
    $res = $db->query("SELECT SUM(tt.task_duration) as task_duration \n\tFROM " . MAIN_DB_PREFIX . "projet_task_time tt LEFT JOIN " . MAIN_DB_PREFIX . "projet_task t ON (tt.fk_task=t.rowid)\n\tWHERE tt.task_date>='" . date('Y-m-d', $t2week) . "' AND t.fk_projet=" . $id_project);
    $velocity = 0;
    if ($obj = $db->fetch_object($res)) {
        $velocity = round($obj->task_duration / ((time() - $t2week) / 86400));
    }
    if ($velocity == 0) {
        $velocity = (int) $conf->global->SCRUM_DEFAULT_VELOCITY * 3600;
    }
    return $velocity;
}
function get_format_libelle_projet($fk)
{
    global $db;
    if ($fk > 0) {
        dol_include_once('/projet/class/project.class.php');
        $o = new Project($db);
        if ($o->fetch($fk) > 0) {
            return $o->getNomUrl(1);
        } else {
            return $fk;
        }
    }
    return '';
}
예제 #9
0
파일: tasks.php 프로젝트: ADDAdev/Dolibarr
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
$langs->load("users");
$langs->load("projects");
$action = GETPOST('action', 'alpha');
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
$mode = GETPOST('mode', 'alpha');
$mine = $mode == 'mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
$object = new Project($db);
$taskstatic = new Task($db);
$extrafields_project = new ExtraFields($db);
$extrafields_task = new ExtraFields($db);
if ($id > 0 || !empty($ref)) {
    $object->fetch($id, $ref);
    $id = $object->id;
    $ref = $object->ref;
    // fetch optionals attributes and labels
    $extralabels_projet = $extrafields_project->fetch_name_optionals_label($object->table_element);
    $extralabels_task = $extrafields_task->fetch_name_optionals_label($taskstatic->table_element);
}
// Security check
$socid = 0;
if ($user->societe_id > 0) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'projet', $id);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('projecttaskcard', 'globalcard'));
$progress = GETPOST('progress', 'int');
<?php

require 'config.php';
dol_include_once('/projet/class/project.class.php');
dol_include_once('/core/lib/project.lib.php');
if (!$user->rights->mandarin->graph->project_task) {
    accessforbidden();
}
$langs->load('mandarin@mandarin');
$progress_min = GETPOST('progress_min', 'int');
$progress_max = GETPOST('progress_max', 'int');
$id = GETPOST('id', 'int');
$object = new Project($db);
if ($id > 0) {
    $object->fetch($id);
}
$PDOdb = new TPDOdb();
$TData = array();
$sql = 'SELECT pt.rowid, pt.label, pt.ref
				, SUM(pt.planned_workload) AS temps_prevu
				, SUM(pt.planned_workload * (pt.progress / 100)) AS temps_theorique
				, SUM(ptt.task_duration) AS temps_reel
				FROM ' . MAIN_DB_PREFIX . 'projet_task pt
				LEFT JOIN ' . MAIN_DB_PREFIX . 'projet_task_time ptt ON (pt.rowid = ptt.fk_task)
				WHERE pt.entity = ' . $conf->entity . '
				AND pt.fk_projet = ' . $id;
if (!empty($progress_min)) {
    $sql .= ' AND pt.progress >= ' . $progress_min;
}
if (!empty($progress_max)) {
    $sql .= ' AND pt.progress >= ' . $progress_max;
예제 #11
0
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
$langs->load("projects");
$langs->load("companies");
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$lineid = GETPOST('lineid', 'int');
$socid = GETPOST('socid', 'int');
$action = GETPOST('action', 'alpha');
$mine = GETPOST('mode') == 'mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
$object = new Project($db);
if ($id > 0 || !empty($ref)) {
    $object->fetch($id, $ref);
    $object->fetch_thirdparty();
    $id = $object->id;
}
// Security check
$socid = 0;
if ($user->societe_id > 0) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'projet', $id);
/*
 * Actions
 */
// Add new contact
if ($action == 'addcontact' && $user->rights->projet->creer) {
    $result = 0;
예제 #12
0
$cancel = GETPOST('cancel', 'alpha');
$status = GETPOST('status', 'int');
$opp_status = GETPOST('opp_status', 'int');
if ($id == '' && $ref == '' && ($action != "create" && $action != "add" && $action != "update" && !$_POST["cancel"])) {
    accessforbidden();
}
$mine = GETPOST('mode') == 'mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('projectcard', 'globalcard'));
$object = new Project($db);
$extrafields = new ExtraFields($db);
// Load object
//include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Can't use generic include because when creating a project, ref is defined and we dont want error if fetch fails from ref.
if ($id > 0 || !empty($ref)) {
    $ret = $object->fetch($id, $ref);
    // If we create project, ref may be defined into POST but record does not yet exists into database
    if ($ret > 0) {
        $object->fetch_thirdparty();
        $id = $object->id;
    }
}
// Security check
$socid = GETPOST('socid');
if ($user->societe_id > 0) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'projet', $object->id);
// fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$date_start = dol_mktime(0, 0, 0, GETPOST('projectstartmonth', 'int'), GETPOST('projectstartday', 'int'), GETPOST('projectstartyear', 'int'));
예제 #13
0
파일: card.php 프로젝트: Albertopf/prueba
         if ($object->contactid && $object->type_code == 'AC_TEL') {
             if ($object->contact->fetch($object->contactid)) {
                 print "<br>" . dol_print_phone($object->contact->phone_pro);
             }
         }
     } else {
         print $langs->trans("None");
     }
     print '</td></tr>';
 }
 // Project
 if (!empty($conf->projet->enabled)) {
     print '<tr><td width="30%">' . $langs->trans("Project") . '</td><td colspan="3">';
     if ($object->fk_project) {
         $project = new Project($db);
         $project->fetch($object->fk_project);
         print $project->getNomUrl(1, '', 1);
     }
     print '</td></tr>';
 }
 // Priority
 print '<tr><td class="nowrap" width="30%">' . $langs->trans("Priority") . '</td><td colspan="3">';
 print $object->priority ? $object->priority : '';
 print '</td></tr>';
 // Object linked
 if (!empty($object->fk_element) && !empty($object->elementtype)) {
     include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
     print '<tr><td>' . $langs->trans("LinkedObject") . '</td>';
     print '<td colspan="3">' . dolGetElementUrl($object->fk_element, $object->elementtype, 1) . '</td></tr>';
 }
 // Description
예제 #14
0
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
    $sortorder = "ASC";
}
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();
예제 #15
0
파일: task.php 프로젝트: ADDAdev/Dolibarr
        if ($ret < 0) {
            $error++;
        }
        if (!$error) {
            $result = $object->update($user);
            if ($result < 0) {
                setEventMessages($object->error, $object->errors, 'errors');
            }
        }
    } else {
        $action = 'edit';
    }
}
if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->projet->supprimer) {
    if ($object->fetch($id, $ref) >= 0) {
        $result = $projectstatic->fetch($object->fk_project);
        $projectstatic->fetch_thirdparty();
        if ($object->delete($user) > 0) {
            header('Location: ' . DOL_URL_ROOT . '/projet/tasks.php?id=' . $projectstatic->id . ($withproject ? '&withproject=1' : ''));
            exit;
        } else {
            setEventMessages($object->error, $object->errors, 'errors');
            $action = '';
        }
    }
}
// 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('', $project_ref) > 0) {
        $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
        if (count($tasksarray) > 0) {
예제 #16
0
 /**
  * Load an object from its id and create a new one in database
  *
  *	@param	int		$fromid     	Id of object to clone
  *	@param	bool	$clone_contact	clone contact of project
  *	@param	bool	$clone_task		clone task of project
  *	@param	bool	$clone_project_file		clone file of project
  *	@param	bool	$clone_task_file		clone file of task (if task are copied)
  *	@param	bool	$clone_note		clone note of project
  *	@param	bool	$notrigger		no trigger flag
  * @return	int						New id of clone
  */
 function createFromClone($fromid, $clone_contact = false, $clone_task = true, $clone_project_file = false, $clone_task_file = false, $clone_note = true, $notrigger = 0)
 {
     global $user, $langs, $conf;
     $error = 0;
     dol_syslog("createFromClone clone_contact=" . $clone_contact . " clone_task=" . $clone_task . " clone_project_file=" . $clone_project_file . " clone_note=" . $clone_note);
     $now = dol_mktime(0, 0, 0, idate('m', dol_now()), idate('d', dol_now()), idate('Y', dol_now()));
     $clone_project = new Project($this->db);
     $clone_project->context['createfromclone'] = 'createfromclone';
     $this->db->begin();
     // Load source object
     $clone_project->fetch($fromid);
     $clone_project->fetch_thirdparty();
     $orign_dt_start = $clone_project->date_start;
     $orign_project_ref = $clone_project->ref;
     $clone_project->id = 0;
     $clone_project->date_start = $now;
     if (!empty($clone_project->date_end)) {
         $clone_project->date_end = $clone_project->date_end + ($now - $orign_dt_start);
     }
     $clone_project->datec = $now;
     if (!$clone_note) {
         $clone_project->note_private = '';
         $clone_project->note_public = '';
     }
     //Generate next ref
     $defaultref = '';
     $obj = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
     if (!empty($conf->global->PROJECT_ADDON) && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/" . $conf->global->PROJECT_ADDON . ".php")) {
         require_once DOL_DOCUMENT_ROOT . "/core/modules/project/" . $conf->global->PROJECT_ADDON . '.php';
         $modProject = new $obj();
         $defaultref = $modProject->getNextValue(is_object($clone_project->thirdparty) ? $clone_project->thirdparty->id : 0, $clone_project);
     }
     if (is_numeric($defaultref) && $defaultref <= 0) {
         $defaultref = '';
     }
     $clone_project->ref = $defaultref;
     // Create clone
     $result = $clone_project->create($user, $notrigger);
     // Other options
     if ($result < 0) {
         $this->error .= $clone_project->error;
         $error++;
     }
     if (!$error) {
         //Get the new project id
         $clone_project_id = $clone_project->id;
         //Note Update
         if (!$clone_note) {
             $clone_project->note_private = '';
             $clone_project->note_public = '';
         } else {
             $this->db->begin();
             $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_public, ENT_QUOTES), '_public');
             if ($res < 0) {
                 $this->error .= $clone_project->error;
                 $error++;
                 $this->db->rollback();
             } else {
                 $this->db->commit();
             }
             $this->db->begin();
             $res = $clone_project->update_note(dol_html_entity_decode($clone_project->note_private, ENT_QUOTES), '_private');
             if ($res < 0) {
                 $this->error .= $clone_project->error;
                 $error++;
                 $this->db->rollback();
             } else {
                 $this->db->commit();
             }
         }
         //Duplicate contact
         if ($clone_contact) {
             $origin_project = new Project($this->db);
             $origin_project->fetch($fromid);
             foreach (array('internal', 'external') as $source) {
                 $tab = $origin_project->liste_contact(-1, $source);
                 foreach ($tab as $contacttoadd) {
                     $clone_project->add_contact($contacttoadd['id'], $contacttoadd['code'], $contacttoadd['source'], $notrigger);
                     if ($clone_project->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
                         $langs->load("errors");
                         $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
                         $error++;
                     } else {
                         if ($clone_project->error != '') {
                             $this->error .= $clone_project->error;
                             $error++;
                         }
                     }
                 }
             }
         }
         //Duplicate file
         if ($clone_project_file) {
             require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
             $clone_project_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($defaultref);
             $ori_project_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($orign_project_ref);
             if (dol_mkdir($clone_project_dir) >= 0) {
                 $filearray = dol_dir_list($ori_project_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', '', SORT_ASC, 1);
                 foreach ($filearray as $key => $file) {
                     $rescopy = dol_copy($ori_project_dir . '/' . $file['name'], $clone_project_dir . '/' . $file['name'], 0, 1);
                     if (is_numeric($rescopy) && $rescopy < 0) {
                         $this->error .= $langs->trans("ErrorFailToCopyFile", $ori_project_dir . '/' . $file['name'], $clone_project_dir . '/' . $file['name']);
                         $error++;
                     }
                 }
             } else {
                 $this->error .= $langs->trans('ErrorInternalErrorDetected') . ':dol_mkdir';
                 $error++;
             }
         }
         //Duplicate task
         if ($clone_task) {
             require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php';
             $taskstatic = new Task($this->db);
             // Security check
             $socid = 0;
             if ($user->societe_id > 0) {
                 $socid = $user->societe_id;
             }
             $tasksarray = $taskstatic->getTasksArray(0, 0, $fromid, $socid, 0);
             //manage new parent clone task id
             $tab_conv_child_parent = array();
             foreach ($tasksarray as $tasktoclone) {
                 $result_clone = $taskstatic->createFromClone($tasktoclone->id, $clone_project_id, $tasktoclone->fk_parent, true, true, false, $clone_task_file, true, false);
                 if ($result_clone <= 0) {
                     $this->error .= $result_clone->error;
                     $error++;
                 } else {
                     $new_task_id = $result_clone;
                     $taskstatic->fetch($tasktoclone->id);
                     //manage new parent clone task id
                     // if the current task has child we store the original task id and the equivalent clone task id
                     if ($taskstatic->hasChildren() && !array_key_exists($tasktoclone->id, $tab_conv_child_parent)) {
                         $tab_conv_child_parent[$tasktoclone->id] = $new_task_id;
                     }
                 }
             }
             //Parse all clone node to be sure to update new parent
             $tasksarray = $taskstatic->getTasksArray(0, 0, $clone_project_id, $socid, 0);
             foreach ($tasksarray as $task_cloned) {
                 $taskstatic->fetch($task_cloned->id);
                 if ($taskstatic->fk_task_parent != 0) {
                     $taskstatic->fk_task_parent = $tab_conv_child_parent[$taskstatic->fk_task_parent];
                 }
                 $res = $taskstatic->update($user, $notrigger);
                 if ($result_clone <= 0) {
                     $this->error .= $taskstatic->error;
                     $error++;
                 }
             }
         }
     }
     unset($clone_project->context['createfromclone']);
     if (!$error) {
         $this->db->commit();
         return $clone_project_id;
     } else {
         $this->db->rollback();
         dol_syslog(get_class($this) . "::createFromClone nbError: " . $error . " error : " . $this->error, LOG_ERR);
         return -1;
     }
 }
예제 #17
0
 /**
  *		Charge le projet d'id $this->fk_project dans this->projet
  *
  *		@return		int			<0 if KO, >=0 if OK
  */
 function fetch_projet()
 {
     if (empty($this->fk_project)) {
         return 0;
     }
     $project = new Project($this->db);
     $result = $project->fetch($this->fk_project);
     $this->projet = $project;
     return $result;
 }
예제 #18
0
$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>";

		// Ref
		print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
예제 #19
0
$result = restrictedArea($user, 'projet', $projectid);


/*
 *	View
 */

$help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
llxHeader("",$langs->trans("Referers"),$help_url);

$form = new Form($db);

$userstatic=new User($db);

$project = new Project($db);
$project->fetch($_GET["id"],$_GET["ref"]);
$project->societe->fetch($project->societe->id);

// To verify role of users
$userAccess = $project->restrictedProjectArea($user);

$head=project_prepare_head($project);
dol_fiche_head($head, 'element', $langs->trans("Project"),0,($project->public?'projectpub':'project'));


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

print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
// Define a complementary filter for search of next/prev ref.
$projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
$project->next_prev_filter=" rowid in (".$projectsListId.")";
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
/**
 *	\file       /scrumboard/scrum.php
 *	\ingroup    projet
 *	\brief      Project card
 */
require 'config.php';
llxHeader('', $langs->trans('Tasks'), '', '', 0, 0, array('/scrumboard/js/scrum.js.php'));
$id_projet = (int) GETPOST('id');
$object = new Project($db);
$object->fetch($id_projet);
// Debug en cas de id 0 et non admin
if (empty($object->id)) {
    $object->id = 0;
}
$object->fetch_thirdparty();
if ($id_projet > 0) {
    $head = project_prepare_head($object);
} else {
    $head = array(0 => array('#', $langs->trans("Scrumboard"), 'scrumboard'));
}
dol_fiche_head($head, 'scrumboard', $langs->trans("Scrumboard"), 0, $object->public ? 'projectpub' : 'project');
$form = new Form($db);
if ($id_projet) {
    /*
     *   Projet synthese pour rappel
예제 #21
0

/* *************************************************************************** */
/*                                                                             */
/* Mode vue et edition                                                         */
/*                                                                             */
/* *************************************************************************** */
if (isset($mesg)) print $mesg;

$id = $_GET['id'];
$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{
	$project = new Project($db);

	if ( $project->fetch($id,$ref) > 0)
	{
		if ($project->societe->id > 0)  $result=$project->societe->fetch($project->societe->id);

		// To verify role of users
		$userAccess = $project->restrictedProjectArea($user);

		$head = project_prepare_head($project);
		dol_fiche_head($head, 'contact', $langs->trans("Project"), 0, ($project->public?'projectpub':'project'));


		/*
		 *   Projet synthese pour rappel
		 */
		print '<table class="border" width="100%">';
 /**
  *	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;
 }
예제 #23
0
if (!isset($_POST['datesrfc']) && !isset($_POST['datesday']) && !empty($conf->global->PROJECT_LINKED_ELEMENT_DEFAULT_FILTER_YEAR)) {
    $new = dol_now();
    $tmp = dol_getdate($new);
    //$datee=$now
    //$dates=dol_time_plus_duree($datee, -1, 'y');
    $dates = dol_get_first_day($tmp['year'], 1);
}
if ($projectid == '' && $ref == '') {
    dol_print_error('', 'Bad parameter');
    exit;
}
$mine = $_REQUEST['mode'] == 'mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
$project = new Project($db);
if ($id > 0 || !empty($ref)) {
    $project->fetch($id, $ref);
    $project->fetch_thirdparty();
    $projectid = $project->id;
} else {
    $project->fetch($projectid);
    $project->fetch_thirdparty();
    $projectid = $project->id;
}
// Security check
$socid = 0;
if ($user->societe_id > 0) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'projet', $projectid);
/*
 *	View
예제 #24
0
파일: time.php 프로젝트: nrjacker4/crm-php
{
	$object->fetchTimeSpent($_GET['lineid']);
	$result = $object->delTimeSpent($user);

	if (!$result)
	{
		$langs->load("errors");
		$mesg='<div class="error">'.$langs->trans($object->error).'</div>';
		$action='';
	}
}

// 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;
		}
		else
		{
			Header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject?'&withproject=1':'').(empty($mode)?'':'&mode='.$mode));
			exit;
		}
	}
}

예제 #25
0
파일: index.php 프로젝트: nrjacker4/crm-php
/*
 * View
 */

$form=new Form($db);
$projectstatic = new Project($db);
$taskstatic = new Task($db);

$title=$langs->trans("Activities");
if ($mine) $title=$langs->trans("MyActivities");

llxHeader("",$title,"Projet");

if ($id)
{
	$projectstatic->fetch($id);
	$projectstatic->societe->fetch($projectstatic->societe->id);
}

print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);

// Show description of content
if ($mine) print $langs->trans("MyProjectsDesc").'<br><br>';
else
{
	if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'<br><br>';
	else print $langs->trans("ProjectsPublicDesc").'<br><br>';
}

// Get list of project id allowed to user
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1,$socid);
 /**
  *	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;
 }
 static function getHeadForObject($tab_object, $fk_object)
 {
     global $db, $conf, $langs, $user;
     $head = array();
     if (empty($tab_object)) {
         return $head;
     }
     if ($tab_object === 'product') {
         dol_include_once('/product/class/product.class.php');
         dol_include_once('/core/lib/product.lib.php');
         $object = new Product($db);
         $object->fetch($fk_object);
         $head = product_prepare_head($object);
     } else {
         if ($tab_object === 'thirdparty') {
             dol_include_once('/societe/class/societe.class.php');
             dol_include_once('/core/lib/company.lib.php');
             $object = new Societe($db);
             $object->fetch($fk_object);
             $head = societe_prepare_head($object);
         } else {
             if ($tab_object === 'contact') {
                 dol_include_once('/contact/class/contact.class.php');
                 dol_include_once('/core/lib/contact.lib.php');
                 $object = new Contact($db);
                 $object->fetch($fk_object);
                 $head = contact_prepare_head($object);
             } else {
                 if ($tab_object === 'user') {
                     dol_include_once('/user/class/user.class.php');
                     dol_include_once('/core/lib/usergroups.lib.php');
                     $object = new User($db);
                     $object->fetch($fk_object);
                     $head = user_prepare_head($object);
                 } else {
                     if ($tab_object === 'group') {
                         dol_include_once('/user/class/usergroup.class.php');
                         dol_include_once('/lib/usergroups.lib.php');
                         $object = new UserGroup($db);
                         $object->fetch($fk_object);
                         $head = group_prepare_head($object);
                     } else {
                         if ($tab_object === 'project') {
                             dol_include_once('/projet/class/project.class.php');
                             dol_include_once('/core/lib/project.lib.php');
                             $object = new Project($db);
                             $object->fetch($fk_object);
                             $head = project_prepare_head($object);
                         }
                     }
                 }
             }
         }
     }
     return $head;
 }
예제 #28
0
파일: perday.php 프로젝트: Albertopf/prueba
$prev_year = $prev['year'];
$prev_month = $prev['mon'];
$prev_day = $prev['mday'];
$next = dol_getdate($daytoparse + 24 * 3600);
$next_year = $next['year'];
$next_month = $next['mon'];
$next_day = $next['mday'];
$title = $langs->trans("TimeSpent");
if ($mine) {
    $title = $langs->trans("MyTimeSpent");
}
$usertoprocess = $user;
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess, 0, 1);
// Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project
if ($id) {
    $project->fetch($id);
    $project->fetch_thirdparty();
}
$onlyopenedproject = 1;
// or -1
$tasksarray = $taskstatic->getTasksArray(0, 0, $project->id ? $project->id : 0, $socid, 0, '', $onlyopenedproject);
// We want to see all task of opened project i am allowed to see, not only mine. Later only mine will be editable later.
$projectsrole = $taskstatic->getUserRolesForProjectsOrTasks($usertoprocess, 0, $project->id ? $project->id : 0, 0, $onlyopenedproject);
$tasksrole = $taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, $project->id ? $project->id : 0, 0, $onlyopenedproject);
//var_dump($tasksarray);
//var_dump($projectsrole);
//var_dump($taskrole);
llxHeader("", $title, "");
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num, '', 'title_project');
$param = $mode ? '&amp;mode=' . $mode : '';
// Show navigation bar
예제 #29
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;
     }
 }
 /**
  *	Show list of documents in a directory
  *
  *  @param	string	$upload_dir         Directory that was scanned
  *  @param  array	$filearray          Array of files loaded by dol_dir_list function before calling this function
  *  @param  string	$modulepart         Value for modulepart used by download wrapper
  *  @param  string	$param              Parameters on sort links
  *  @param  int		$forcedownload      Force to open dialog box "Save As" when clicking on file
  *  @param  string	$relativepath       Relative path of docs (autodefined if not provided)
  *  @param  int		$permtodelete       Permission to delete
  *  @param  int		$useinecm           Change output for use in ecm module
  *  @param  int		$textifempty        Text to show if filearray is empty
  *  @param  int		$maxlength          Maximum length of file name shown
  *  @param	string $url				Full url to use for click links ('' = autodetect)
  *  @return int                 		<0 if KO, nb of files shown if OK
  */
 function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permtodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $url = '')
 {
     global $user, $conf, $langs;
     global $bc;
     global $sortfield, $sortorder;
     dol_syslog(get_class($this) . '::list_of_autoecmfiles upload_dir=' . $upload_dir . ' modulepart=' . $modulepart);
     // Show list of documents
     if (empty($useinecm)) {
         print_titre($langs->trans("AttachedFiles"));
     }
     if (empty($url)) {
         $url = $_SERVER["PHP_SELF"];
     }
     print '<table width="100%" class="nobordernopadding">';
     print '<tr class="liste_titre">';
     $sortref = "fullname";
     if ($modulepart == 'invoice_supplier') {
         $sortref = 'level1name';
     }
     print_liste_field_titre($langs->trans("Ref"), $url, $sortref, "", $param, 'align="left"', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("Documents2"), $url, "name", "", $param, 'align="left"', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("Size"), $url, "size", "", $param, 'align="right"', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("Date"), $url, "date", "", $param, 'align="center"', $sortfield, $sortorder);
     print_liste_field_titre('', '', '');
     print '</tr>';
     // To show ref or specific information according to view to show (defined by $module)
     if ($modulepart == 'company') {
         include_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
         $object_instance = new Societe($this->db);
     } else {
         if ($modulepart == 'invoice') {
             include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
             $object_instance = new Facture($this->db);
         } else {
             if ($modulepart == 'invoice_supplier') {
                 include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
                 $object_instance = new FactureFournisseur($this->db);
             } else {
                 if ($modulepart == 'propal') {
                     include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
                     $object_instance = new Propal($this->db);
                 } else {
                     if ($modulepart == 'order') {
                         include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
                         $object_instance = new Commande($this->db);
                     } else {
                         if ($modulepart == 'order_supplier') {
                             include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
                             $object_instance = new CommandeFournisseur($this->db);
                         } else {
                             if ($modulepart == 'contract') {
                                 include_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php';
                                 $object_instance = new Contrat($this->db);
                             } else {
                                 if ($modulepart == 'product') {
                                     include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
                                     $object_instance = new Product($this->db);
                                 } else {
                                     if ($modulepart == 'tax') {
                                         include_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php';
                                         $object_instance = new ChargeSociales($this->db);
                                     } else {
                                         if ($modulepart == 'project') {
                                             include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
                                             $object_instance = new Project($this->db);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $var = true;
     foreach ($filearray as $key => $file) {
         if (!is_dir($file['name']) && $file['name'] != '.' && $file['name'] != '..' && $file['name'] != 'CVS' && !preg_match('/\\.meta$/i', $file['name'])) {
             // Define relative path used to store the file
             $relativefile = preg_replace('/' . preg_quote($upload_dir . '/', '/') . '/', '', $file['fullname']);
             //var_dump($file);
             $id = 0;
             $ref = '';
             $label = '';
             // To show ref or specific information according to view to show (defined by $module)
             if ($modulepart == 'company') {
                 preg_match('/(\\d+)\\/[^\\/]+$/', $relativefile, $reg);
                 $id = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'invoice') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'invoice_supplier') {
                 preg_match('/([^\\/]+)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
                 if (is_numeric($ref)) {
                     $id = $ref;
                     $ref = '';
                 }
             }
             // $ref may be also id with old supplier invoices
             if ($modulepart == 'propal') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'order') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'order_supplier') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'contract') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'product') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'tax') {
                 preg_match('/(\\d+)\\/[^\\/]+$/', $relativefile, $reg);
                 $id = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'project') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
             }
             if (!$id && !$ref) {
                 continue;
             }
             $found = 0;
             if (!empty($this->cache_objects[$modulepart . '_' . $id . '_' . $ref])) {
                 $found = 1;
             } else {
                 //print 'Fetch '.$id." - ".$ref.'<br>';
                 $result = $object_instance->fetch($id, $ref);
                 if ($result > 0) {
                     $found = 1;
                     $this->cache_objects[$modulepart . '_' . $id . '_' . $ref] = dol_clone($object_instance);
                 }
                 // Save object into a cache
                 if ($result == 0) {
                     $found = 1;
                     $this->cache_objects[$modulepart . '_' . $id . '_' . $ref] = 'notfound';
                     unset($filearray[$key]);
                 }
             }
             if (!$found > 0 || !is_object($this->cache_objects[$modulepart . '_' . $id . '_' . $ref])) {
                 continue;
             }
             // We do not show orphelins files
             $var = !$var;
             print '<tr ' . $bc[$var] . '>';
             print '<td>';
             if ($found > 0 && is_object($this->cache_objects[$modulepart . '_' . $id . '_' . $ref])) {
                 print $this->cache_objects[$modulepart . '_' . $id . '_' . $ref]->getNomUrl(1, 'document');
             } else {
                 print $langs->trans("ObjectDeleted", $id ? $id : $ref);
             }
             print '</td>';
             print '<td>';
             //print "XX".$file['name']; //$file['name'] must be utf8
             print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart;
             if ($forcedownload) {
                 print '&attachment=1';
             }
             print '&file=' . urlencode($relativefile) . '">';
             print img_mime($file['name'], $file['name'] . ' (' . dol_print_size($file['size'], 0, 0) . ')') . ' ';
             print dol_trunc($file['name'], $maxlength, 'middle');
             print '</a>';
             print "</td>\n";
             print '<td align="right">' . dol_print_size($file['size'], 1, 1) . '</td>';
             print '<td align="center">' . dol_print_date($file['date'], "dayhour") . '</td>';
             print '<td align="right">';
             if (!empty($useinecm)) {
                 print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart;
             }
             if ($forcedownload) {
                 print '&attachment=1';
             }
             print '&file=' . urlencode($relativefile) . '">';
             print img_view() . '</a> &nbsp; ';
             //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
             //else print '&nbsp;';
             print "</td></tr>\n";
         }
     }
     if (count($filearray) == 0) {
         print '<tr ' . $bc[$var] . '><td colspan="4">';
         if (empty($textifempty)) {
             print $langs->trans("NoFileFound");
         } else {
             print $textifempty;
         }
         print '</td></tr>';
     }
     print "</table>";
     // Fin de zone
 }