/**
  *		Function called when module is enabled.
  *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  *		It also creates data directories.
  *      @return     int             1 if OK, 0 if KO
  */
 function init()
 {
     global $db, $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $dirodt = DOL_DATA_ROOT . '/produit';
     dol_mkdir($dirodt);
     dol_copy(dol_buildpath('/pos/frontend/img/noimage.jpg', 0), $dirodt . '/noimage.jpg', 0, 0);
     if (empty($conf->global->POS_TICKET) && empty($conf->global->POS_FACTURE)) {
         dolibarr_set_const($db, "POS_FACTURE", '1', 'chaine', 0, '', $conf->entity);
     }
     if (empty($conf->global->POS_MAX_TTC)) {
         dolibarr_set_const($db, "POS_MAX_TTC", '100', 'chaine', 0, '', $conf->entity);
     }
     $sql = array();
     $result = $this->load_tables();
     return $this->_init($sql);
 }
Example #2
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;
     }
 }
Example #3
0
 /**
  *		Function called when module is enabled.
  *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  *		It also creates data directories
  *
  *      @param      string	$options    Options when enabling module ('', 'noboxes')
  *      @return     int             	1 if OK, 0 if KO
  */
 function init($options = '')
 {
     global $conf, $langs;
     // Permissions
     $this->remove($options);
     //ODT template
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $dirodt = DOL_DATA_ROOT . '/doctemplates/orders';
     dol_mkdir($dirodt);
     $src = DOL_DOCUMENT_ROOT . '/install/doctemplates/orders/template_order.odt';
     $dest = $dirodt . '/template_order.odt';
     $result = dol_copy($src, $dest, 0, 0);
     if ($result < 0) {
         $langs->load("errors");
         $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
         return 0;
     }
     $sql = array("DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = '" . $this->const[0][2] . "' AND entity = " . $conf->entity, "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->const[0][2] . "','order'," . $conf->entity . ")");
     return $this->_init($sql, $options);
 }
Example #4
0
						$existt=dol_is_file($filetarget);
						if (! $existt)
						{
							dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos');

							print "  &nbsp; &nbsp; &nbsp; -> Copy file ".$filetotest." -> ".$filetarget."<br>\n";
							dol_copy($filetotest, $filetarget, '', 0);
						}

						$existtt=dol_is_file($filetargetsmall);
						if (! $existtt)
						{
							dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs');

							print "  &nbsp; &nbsp; &nbsp; -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."<br>\n";
							dol_copy($filetotestsmall, $filetargetsmall, '', 0);
						}
					}
				}

				$i++;
			}
		}
		else
		{
			$ok=0;
			dol_print_error($db);
		}
	//}
}
 /**
  *		Function called when module is enabled.
  *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  *		It also creates data directories
  *
  *      @param      string	$options    Options when enabling module ('', 'noboxes')
  *      @return     int             	1 if OK, 0 if KO
  */
 function init($options = '')
 {
     global $conf, $langs;
     // We disable this to prevent pb of modules not correctly disabled
     //$this->remove($options);
     //ODT template
     $src = DOL_DOCUMENT_ROOT . '/install/doctemplates/thirdparties/template_thirdparty.odt';
     $dirodt = DOL_DATA_ROOT . '/doctemplates/thirdparties';
     $dest = $dirodt . '/template_thirdparty.odt';
     if (file_exists($src) && !file_exists($dest)) {
         require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
         dol_mkdir($dirodt);
         $result = dol_copy($src, $dest, 0, 0);
         if ($result < 0) {
             $langs->load("errors");
             $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
             return 0;
         }
     }
     $sql = array();
     return $this->_init($sql, $options);
 }
Example #6
0
 // Table prefix
 $main_db_prefix = !empty($db_prefix) ? $db_prefix : 'llx_';
 // Force https
 $main_force_https = GETPOST("main_force_https") && (GETPOST("main_force_https") == "on" || GETPOST("main_force_https") == 1) ? '1' : '0';
 // Use alternative directory
 $main_use_alt_dir = GETPOST("main_use_alt_dir") && (GETPOST("main_use_alt_dir") == "on" || GETPOST("main_use_alt_dir") == 1) ? '' : '//';
 // Alternative root directory name
 $main_alt_dir_name = GETPOST("main_alt_dir_name") && GETPOST("main_alt_dir_name") != '' ? GETPOST("main_alt_dir_name") : 'custom';
 // Write conf file on disk
 if (!$error) {
     // Save old conf file on disk
     if (file_exists("{$conffile}")) {
         // We must ignore errors as an existing old file may already exists and not be replacable or
         // the installer (like for ubuntu) may not have permission to create another file than conf.php.
         // Also no other process must be able to read file or we expose the new file, so content with password.
         @dol_copy($conffile, $conffile . '.old', '0400');
     }
     $error += write_conf_file($conffile);
 }
 // Write main.inc.php and master.inc.php into documents/custom dir
 $error += write_main_file($main_data_dir . '/custom/main.inc.php', $main_dir);
 $error += write_master_file($main_data_dir . '/custom/master.inc.php', $main_dir);
 // Create database and admin user database
 if (!$error) {
     // We reload configuration file
     conf($dolibarr_main_document_root);
     print '<tr><td>';
     print $langs->trans("ConfFileReload");
     print '</td>';
     print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
     $userroot = isset($_POST["db_user_root"]) ? $_POST["db_user_root"] : "";
Example #7
0
	/**
	 *  Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module.
	 *  Definit egalement les repertoires de donnees a creer pour ce module.
	 *	@param		options		Options when enabling module
	 */
	function init($options='')
	{
		global $conf;

		// Remove permissions and default values
		$this->remove($options);

		require_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
		$dirodt=DOL_DATA_ROOT.'/doctemplates/invoices';
		create_exdir($dirodt);
		dol_copy(DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt',$dirodt.'/template_invoice.odt',0,0);

		$sql = array(
			 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
			 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','invoice',".$conf->entity.")",
		);

		return $this->_init($sql,$options);
	}
Example #8
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;
     }
 }
Example #9
0
    /**
     *      Function called when module is enabled.
     *      The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
     *      It also creates data directories.
     *      @return     int             1 if OK, 0 if KO
     */
	function init($options='')
	{
		global $conf;

		// We disable this to prevent pb of modules not correctly disabled
		//$this->remove($options);

		require_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
		$dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
		create_exdir($dirodt);
		dol_copy(DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt',$dirodt.'/template_thirdparty.odt',0,0);

		$sql = array();

		return $this->_init($sql,$options);
	}
Example #10
0
/**
 * Copy a dir to another dir.
 *
 * @param	string	$srcfile			Source file (a directory)
 * @param	string	$destfile			Destination file (a directory)
 * @param	int		$newmask			Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
 * @param 	int		$overwriteifexists	Overwrite file if exists (1 by default)
 * @return	int							<0 if error, 0 if nothing done (dest dir already exists and overwriteifexists=0), >0 if OK
 * @see		dol_copy
 */
function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists)
{
    global $conf;
    $result = 0;
    dol_syslog("files.lib.php::dolCopyr srcfile=" . $srcfile . " destfile=" . $destfile . " newmask=" . $newmask . " overwriteifexists=" . $overwriteifexists);
    if (empty($srcfile) || empty($destfile)) {
        return -1;
    }
    $destexists = dol_is_dir($destfile);
    if (!$overwriteifexists && $destexists) {
        return 0;
    }
    $srcfile = dol_osencode($srcfile);
    $destfile = dol_osencode($destfile);
    // recursive function to copy
    // all subdirectories and contents:
    if (is_dir($srcfile)) {
        $dir_handle = opendir($srcfile);
        while ($file = readdir($dir_handle)) {
            if ($file != "." && $file != "..") {
                if (is_dir($srcfile . "/" . $file)) {
                    if (!is_dir($destfile . "/" . $file)) {
                        umask(0);
                        $dirmaskdec = octdec($newmask);
                        if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
                            $dirmaskdec = octdec($conf->global->MAIN_UMASK);
                        }
                        $dirmaskdec |= octdec('0200');
                        // Set w bit required to be able to create content for recursive subdirs files
                        dol_mkdir($destfile . "/" . $file, '', decoct($dirmaskdec));
                    }
                    $result = dolCopyDir($srcfile . "/" . $file, $destfile . "/" . $file, $newmask, $overwriteifexists);
                } else {
                    $result = dol_copy($srcfile . "/" . $file, $destfile . "/" . $file, $newmask, $overwriteifexists);
                }
                if ($result < 0) {
                    break;
                }
            }
        }
        closedir($dir_handle);
    } else {
        $result = dol_copy($srcfile, $destfile, $newmask, $overwriteifexists);
    }
    return $result;
}
Example #11
0
    /**
     * testDolCopyMove
     *
     * @return	int
     */
    public function testDolCopyMove()
    {
        global $conf,$user,$langs,$db;
        $conf=$this->savconf;
        $user=$this->savuser;
        $langs=$this->savlangs;
        $db=$this->savdb;

        $file=dirname(__FILE__).'/Example_import_company_1.csv';

        $result=dol_copy($file, '/adir/that/does/not/exists/file.csv');
        print __METHOD__." result=".$result."\n";
        $this->assertLessThan(0,$result);    // We should have error

        $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1);
        print __METHOD__." result=".$result."\n";
        $this->assertGreaterThanOrEqual(1,$result);    // Should be 1

        // Again to test with overwriting=0
        $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,0);
        print __METHOD__." result=".$result."\n";
        $this->assertEquals(0,$result);    // Should be 0

        // Again to test with overwriting=1
        $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1);
        print __METHOD__." result=".$result."\n";
        $this->assertGreaterThanOrEqual(1,$result);    // Should be 1

        // Again to test with overwriting=1
        $result=dol_move($conf->admin->dir_temp.'/file.csv',$conf->admin->dir_temp.'/file2.csv',0,1);
        print __METHOD__." result=".$result."\n";
        $this->assertTrue($result);

        $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv');
        print __METHOD__." result=".$result."\n";
        $this->assertTrue($result);

        // Again to test no erreor when deleteing a non existing file
        $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv');
        print __METHOD__." result=".$result."\n";
        $this->assertTrue($result);
    }