/**
  * Constructor
  *
  * @param array		$options		Options array
  * @param int		$fk_element		fk_element
  * @param string	$element		element
  */
 function __construct($options = null, $fk_element = null, $element = null)
 {
     global $db, $conf;
     global $object;
     $this->fk_element = $fk_element;
     $this->element = $element;
     $pathname = $filename = $element;
     if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) {
         $pathname = $regs[1];
         $filename = $regs[2];
     }
     $parentForeignKey = '';
     // For compatibility
     if ($element == 'propal') {
         $pathname = 'comm/propal';
         $dir_output = $conf->{$element}->dir_output;
     } elseif ($element == 'facture') {
         $pathname = 'compta/facture';
         $dir_output = $conf->{$element}->dir_output;
     } elseif ($element == 'project') {
         $element = $pathname = 'projet';
         $dir_output = $conf->{$element}->dir_output;
     } elseif ($element == 'project_task') {
         $pathname = 'projet';
         $filename = 'task';
         $dir_output = $conf->projet->dir_output;
         $parentForeignKey = 'fk_project';
         $parentClass = 'Project';
         $parentElement = 'projet';
         $parentObject = 'project';
     } elseif ($element == 'fichinter') {
         $element = 'ficheinter';
         $dir_output = $conf->{$element}->dir_output;
     } elseif ($element == 'order_supplier') {
         $pathname = 'fourn';
         $filename = 'fournisseur.commande';
         $dir_output = $conf->fournisseur->commande->dir_output;
     } elseif ($element == 'invoice_supplier') {
         $pathname = 'fourn';
         $filename = 'fournisseur.facture';
         $dir_output = $conf->fournisseur->facture->dir_output;
     } elseif ($element == 'product') {
         $dir_output = $conf->product->multidir_output[$conf->entity];
     } elseif ($element == 'action') {
         $pathname = 'comm/action';
         $filename = 'actioncomm';
         $dir_output = $conf->agenda->dir_output;
     } elseif ($element == 'chargesociales') {
         $pathname = 'compta/sociales';
         $filename = 'chargesociales';
         $dir_output = $conf->tax->dir_output;
     } else {
         $dir_output = $conf->{$element}->dir_output;
     }
     dol_include_once('/' . $pathname . '/class/' . $filename . '.class.php');
     $classname = ucfirst($filename);
     if ($element == 'order_supplier') {
         $classname = 'CommandeFournisseur';
     } elseif ($element == 'invoice_supplier') {
         $classname = 'FactureFournisseur';
     }
     $object = new $classname($db);
     $object->fetch($fk_element);
     if (!empty($parentForeignKey)) {
         dol_include_once('/' . $parentElement . '/class/' . $parentObject . '.class.php');
         $parent = new $parentClass($db);
         $parent->fetch($object->{$parentForeignKey});
         if (!empty($parent->socid)) {
             $parent->fetch_thirdparty();
         }
         $object->{$parentObject} = dol_clone($parent);
     } else {
         $object->fetch_thirdparty();
     }
     $object_ref = dol_sanitizeFileName($object->ref);
     if ($element == 'invoice_supplier') {
         $object_ref = get_exdir($object->id, 2) . $object_ref;
     } else {
         if ($element == 'project_task') {
             $object_ref = $object->project->ref . '/' . $object_ref;
         }
     }
     $this->options = array('script_url' => $_SERVER['PHP_SELF'], 'upload_dir' => $dir_output . '/' . $object_ref . '/', 'upload_url' => DOL_URL_ROOT . '/document.php?modulepart=' . $element . '&attachment=1&file=/' . $object_ref . '/', 'param_name' => 'files', 'delete_type' => 'DELETE', 'max_file_size' => null, 'min_file_size' => 1, 'accept_file_types' => '/.+$/i', 'max_number_of_files' => null, 'max_width' => null, 'max_height' => null, 'min_width' => 1, 'min_height' => 1, 'discard_aborted_uploads' => true, 'image_versions' => array('thumbnail' => array('upload_dir' => $dir_output . '/' . $object_ref . '/thumbs/', 'upload_url' => DOL_URL_ROOT . '/document.php?modulepart=' . $element . '&attachment=1&file=/' . $object_ref . '/thumbs/', 'max_width' => 80, 'max_height' => 80)));
     if ($options) {
         $this->options = array_replace_recursive($this->options, $options);
     }
 }
 /**
  *	Load an object from its id and create a new one in database
  *
  *	@return		int							New id of clone
  */
 function createFromClone()
 {
     global $conf, $user, $langs, $hookmanager;
     $error = 0;
     $this->context['createfromclone'] = 'createfromclone';
     $this->db->begin();
     // Load source object
     $objFrom = dol_clone($this);
     $this->id = 0;
     $this->statut = 0;
     // Clear fields
     $this->user_author_id = $user->id;
     $this->user_valid = '';
     $this->date_creation = '';
     $this->date_validation = '';
     $this->ref_supplier = '';
     // Create clone
     $result = $this->create($user);
     if ($result < 0) {
         $error++;
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Call trigger
         $result = $this->call_trigger('ORDER_SUPPLIER_CLONE', $user);
         if ($result < 0) {
             $error++;
         }
         // End call triggers
     }
     unset($this->context['createfromclone']);
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Пример #3
0
     $action = '';
 }
 include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php';
 // Must be include, not include_once
 include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
 // Must be include, not include_once
 include DOL_DOCUMENT_ROOT . '/core/actions_lineupdown.inc.php';
 // Must be include, not include_once
 // Action clone object
 if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->commande->creer) {
     if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
         setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
     } else {
         if ($object->id > 0) {
             // Because createFromClone modifies the object, we must clone it so that we can restore it later
             $orig = dol_clone($object);
             $result = $object->createFromClone($socid);
             if ($result > 0) {
                 header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result);
                 exit;
             } else {
                 setEventMessage($object->error, 'errors');
                 $object = $orig;
                 $action = '';
             }
         }
     }
 } else {
     if ($action == 'reopen' && $user->rights->commande->creer) {
         if ($object->statut == Commande::STATUS_CANCELED || $object->statut == Commande::STATUS_CLOSED) {
             $result = $object->set_reopen($user);
 /**
  *      Build export file.
  *      File is built into directory $conf->export->dir_temp.'/'.$user->id
  *      Arrays this->array_export_xxx are already loaded for required datatoexport
  *
  *      @param      User		$user               User that export
  *      @param      string		$model              Export format
  *      @param      string		$datatoexport       Name of dataset to export
  *      @param      array		$array_selected     Filter on array of fields to export
  *      @param      array		$array_filterValue  Filter on array of fields with a filter
  *      @param		string		$sqlquery			If set, transmit the sql request for select (otherwise, sql request is generated from arrays)
  *      @return		int								<0 if KO, >0 if OK
  */
 function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '')
 {
     global $conf, $langs;
     $indice = 0;
     asort($array_selected);
     dol_syslog(get_class($this) . "::" . __FUNCTION__ . " " . $model . ", " . $datatoexport . ", " . implode(",", $array_selected));
     // Check parameters or context properties
     if (empty($this->array_export_fields) || !is_array($this->array_export_fields)) {
         $this->error = "ErrorBadParameter";
         return -1;
     }
     // Creation de la classe d'export du model ExportXXX
     $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
     $file = "export_" . $model . ".modules.php";
     $classname = "Export" . $model;
     require_once $dir . $file;
     $objmodel = new $classname($this->db);
     if (!empty($sqlquery)) {
         $sql = $sqlquery;
     } else {
         // Define value for indice from $datatoexport
         $foundindice = 0;
         foreach ($this->array_export_code as $key => $dataset) {
             if ($datatoexport == $dataset) {
                 $indice = $key;
                 $foundindice++;
                 //print "Found indice = ".$indice." for dataset=".$datatoexport."\n";
                 break;
             }
         }
         if (empty($foundindice)) {
             $this->error = "ErrorBadParameter can't find dataset " . $datatoexport . " into preload arrays this->array_export_code";
             return -1;
         }
         $sql = $this->build_sql($indice, $array_selected, $array_filterValue);
     }
     // Run the sql
     $this->sqlusedforexport = $sql;
     dol_syslog(get_class($this) . "::" . __FUNCTION__ . " sql=" . $sql);
     $resql = $this->db->query($sql);
     if ($resql) {
         //$this->array_export_label[$indice]
         $filename = "export_" . $datatoexport;
         $filename .= '.' . $objmodel->getDriverExtension();
         $dirname = $conf->export->dir_temp . '/' . $user->id;
         $outputlangs = dol_clone($langs);
         // We clone to have an object we can modify (for example to change output charset by csv handler) without changing original value
         // Open file
         dol_mkdir($dirname);
         $result = $objmodel->open_file($dirname . "/" . $filename, $outputlangs);
         if ($result >= 0) {
             // Genere en-tete
             $objmodel->write_header($outputlangs);
             // Genere ligne de titre
             $objmodel->write_title($this->array_export_fields[$indice], $array_selected, $outputlangs, $this->array_export_TypeFields[$indice]);
             $var = true;
             while ($objp = $this->db->fetch_object($resql)) {
                 $var = !$var;
                 // Process special operations
                 if (!empty($this->array_export_special[$indice])) {
                     foreach ($this->array_export_special[$indice] as $key => $value) {
                         if (!array_key_exists($key, $array_selected)) {
                             continue;
                         }
                         // Field not selected
                         // Operation NULLIFNEG
                         if ($this->array_export_special[$indice][$key] == 'NULLIFNEG') {
                             //$alias=$this->array_export_alias[$indice][$key];
                             $alias = str_replace(array('.', '-'), '_', $key);
                             if ($objp->{$alias} < 0) {
                                 $objp->{$alias} = '';
                             }
                         }
                         // Operation ZEROIFNEG
                         if ($this->array_export_special[$indice][$key] == 'ZEROIFNEG') {
                             //$alias=$this->array_export_alias[$indice][$key];
                             $alias = str_replace(array('.', '-'), '_', $key);
                             if ($objp->{$alias} < 0) {
                                 $objp->{$alias} = '0';
                             }
                         }
                     }
                 }
                 // end of special operation processing
                 $objmodel->write_record($array_selected, $objp, $outputlangs, $this->array_export_TypeFields[$indice]);
             }
             // Genere en-tete
             $objmodel->write_footer($outputlangs);
             // Close file
             $objmodel->close_file();
             return 1;
         } else {
             $this->error = $objmodel->error;
             dol_syslog("Export::build_file Error: " . $this->error, LOG_ERR);
             return -1;
         }
     } else {
         $this->error = $this->db->error() . " - sql=" . $sql;
         dol_syslog("Export::build_file Error: " . $this->error, LOG_ERR);
         return -1;
     }
 }
 /**
  *	Load data control
  *
  *	@param	int		$action	Action code
  *	@return	void
  */
 function doActions(&$action)
 {
     global $conf, $user, $langs;
     if ($_POST["getcustomercode"]) {
         // We defined value code_client
         $_POST["code_client"] = "Acompleter";
     }
     if ($_POST["getsuppliercode"]) {
         // We defined value code_fournisseur
         $_POST["code_fournisseur"] = "Acompleter";
     }
     // Add new third party
     if (!$_POST["getcustomercode"] && !$_POST["getsuppliercode"] && ($action == 'add' || $action == 'update')) {
         require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
         $error = 0;
         if (GETPOST("private") == 1) {
             $this->object->particulier = GETPOST("private");
             $this->object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? trim($_POST["firstname"] . ' ' . $_POST["lastname"]) : trim($_POST["lastname"] . ' ' . $_POST["firstname"]);
             $this->object->civility_id = $_POST["civility_id"];
             // Add non official properties
             $this->object->name_bis = $_POST["lastname"];
             $this->object->firstname = $_POST["firstname"];
         } else {
             $this->object->name = $_POST["nom"];
         }
         $this->object->address = $_POST["adresse"];
         $this->object->zip = $_POST["zipcode"];
         $this->object->town = $_POST["town"];
         $this->object->country_id = $_POST["country_id"];
         $this->object->state_id = $_POST["state_id"];
         $this->object->phone = $_POST["tel"];
         $this->object->fax = $_POST["fax"];
         $this->object->email = trim($_POST["email"]);
         $this->object->url = $_POST["url"];
         $this->object->idprof1 = $_POST["idprof1"];
         $this->object->idprof2 = $_POST["idprof2"];
         $this->object->idprof3 = $_POST["idprof3"];
         $this->object->idprof4 = $_POST["idprof4"];
         $this->object->prefix_comm = $_POST["prefix_comm"];
         $this->object->code_client = $_POST["code_client"];
         $this->object->code_fournisseur = $_POST["code_fournisseur"];
         $this->object->capital = $_POST["capital"];
         $this->object->barcode = $_POST["barcode"];
         $this->object->canvas = GETPOST("canvas");
         $this->object->tva_assuj = $_POST["assujtva_value"];
         // Local Taxes
         $this->object->localtax1_assuj = $_POST["localtax1assuj_value"];
         $this->object->localtax2_assuj = $_POST["localtax2assuj_value"];
         $this->object->tva_intra = $_POST["tva_intra"];
         $this->object->forme_juridique_code = $_POST["forme_juridique_code"];
         $this->object->effectif_id = $_POST["effectif_id"];
         if (GETPOST("private") == 1) {
             $this->object->typent_id = dol_getIdFromCode($db, 'TE_PRIVATE', 'c_typent');
         } else {
             $this->object->typent_id = $_POST["typent_id"];
         }
         $this->object->client = $_POST["client"];
         $this->object->fournisseur = $_POST["fournisseur"];
         $this->object->commercial_id = $_POST["commercial_id"];
         $this->object->default_lang = $_POST["default_lang"];
         // Check parameters
         if (empty($_POST["cancel"])) {
             if (!empty($this->object->email) && !isValidEMail($this->object->email)) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorBadEMail", $this->object->email);
                 $action = $action == 'add' ? 'create' : 'edit';
             }
             if (!empty($this->object->url) && !isValidUrl($this->object->url)) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorBadUrl", $this->object->url);
                 $action = $action == 'add' ? 'create' : 'edit';
             }
             if ($this->object->fournisseur && !$conf->fournisseur->enabled) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
                 $action = $action == 'add' ? 'create' : 'edit';
             }
         }
         if (!$error) {
             if ($action == 'add') {
                 $this->db->begin();
                 if (empty($this->object->client)) {
                     $this->object->code_client = '';
                 }
                 if (empty($this->object->fournisseur)) {
                     $this->object->code_fournisseur = '';
                 }
                 $result = $this->object->create($user);
                 if ($result >= 0) {
                     if ($this->object->particulier) {
                         dol_syslog(get_class($this) . "::doActions This thirdparty is a personal people", LOG_DEBUG);
                         $contact = new Contact($this->db);
                         $contact->civility_id = $this->object->civility_id;
                         $contact->name = $this->object->name_bis;
                         $contact->firstname = $this->object->firstname;
                         $contact->address = $this->object->address;
                         $contact->zip = $this->object->zip;
                         $contact->town = $this->object->town;
                         $contact->country_id = $this->object->country_id;
                         $contact->socid = $this->object->id;
                         // fk_soc
                         $contact->status = 1;
                         $contact->email = $this->object->email;
                         $contact->priv = 0;
                         $result = $contact->create($user);
                     }
                 } else {
                     $this->errors = $this->object->errors;
                 }
                 if ($result >= 0) {
                     $this->db->commit();
                     if ($this->object->client == 1) {
                         header("Location: " . DOL_URL_ROOT . "/comm/fiche.php?socid=" . $this->object->id);
                         return;
                     } else {
                         if ($this->object->fournisseur == 1) {
                             header("Location: " . DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $this->object->id);
                             return;
                         } else {
                             header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                             return;
                         }
                     }
                     exit;
                 } else {
                     $this->db->rollback();
                     $this->errors = $this->object->errors;
                     $action = 'create';
                 }
             }
             if ($action == 'update') {
                 if ($_POST["cancel"]) {
                     header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                     exit;
                 }
                 $oldsoccanvas = dol_clone($this->object);
                 // To avoid setting code if third party is not concerned. But if it had values, we keep them.
                 if (empty($this->object->client) && empty($oldsoccanvas->code_client)) {
                     $this->object->code_client = '';
                 }
                 if (empty($this->object->fournisseur) && empty($oldsoccanvas->code_fournisseur)) {
                     $this->object->code_fournisseur = '';
                 }
                 $result = $this->object->update($this->object->id, $user, 1, $oldsoccanvas->codeclient_modifiable(), $oldsoccanvas->codefournisseur_modifiable());
                 if ($result >= 0) {
                     header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                     exit;
                 } else {
                     $reload = 0;
                     $this->errors = $this->object->errors;
                     $action = "edit";
                 }
             }
         }
     }
     if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
         $result = $this->object->delete($this->object->id);
         if ($result >= 0) {
             header("Location: " . DOL_URL_ROOT . "/societe/societe.php?delsoc=" . $this->object->nom . "");
             exit;
         } else {
             $reload = 0;
             $this->errors = $this->object->errors;
             $action = '';
         }
     }
     /*
      * Generate document
      */
     if ($action == 'builddoc') {
         if (is_numeric(GETPOST('model'))) {
             $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model"));
         } else {
             require_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php';
             $this->object->fetch_thirdparty();
             // Define output language
             $outputlangs = $langs;
             $newlang = '';
             if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) {
                 $newlang = GETPOST('lang_id');
             }
             if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
                 $newlang = $this->object->default_lang;
             }
             if (!empty($newlang)) {
                 $outputlangs = new Translate("", $conf);
                 $outputlangs->setDefaultLang($newlang);
             }
             $result = thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model', 'alpha'), $outputlangs);
             if ($result <= 0) {
                 dol_print_error($this->db, $result);
                 exit;
             }
         }
     }
 }
 /**
  *	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 == 'askpricesupplier') {
                         include_once DOL_DOCUMENT_ROOT . '/comm/askpricesupplier/class/askpricesupplier.class.php';
                         $object_instance = new AskPriceSupplier($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);
                                             } else {
                                                 if ($modulepart == 'fichinter') {
                                                     include_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php';
                                                     $object_instance = new Fichinter($this->db);
                                                 } else {
                                                     if ($modulepart == 'user') {
                                                         include_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
                                                         $object_instance = new User($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 == 'askpricesupplier') {
                 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 ($modulepart == 'fichinter') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $ref = isset($reg[1]) ? $reg[1] : '';
             }
             if ($modulepart == 'user') {
                 preg_match('/(.*)\\/[^\\/]+$/', $relativefile, $reg);
                 $id = 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>';
                 if ($id) {
                     $result = $object_instance->fetch($id);
                 } else {
                     //fetchOneLike looks for objects with wildcards in its reference.
                     //It is useful for those masks who get underscores instead of their actual symbols
                     //fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned
                     //that's why we look only look fetchOneLike when fetch returns 0
                     if (!($result = $object_instance->fetch('', $ref))) {
                         $result = $object_instance->fetchOneLike($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[false] . '><td colspan="4">';
         if (empty($textifempty)) {
             print $langs->trans("NoFileFound");
         } else {
             print $textifempty;
         }
         print '</td></tr>';
     }
     print "</table>";
     // Fin de zone
 }
Пример #7
0
 /**
  *		Load an object from its id and create a new one in database
  *
  *		@param		int				$socid			Id of thirdparty
  * 	 	@return		int								New id of clone
  */
 function createFromClone($socid = 0)
 {
     global $user, $langs, $conf, $hookmanager;
     $this->context['createfromclone'] = 'createfromclone';
     $error = 0;
     $now = dol_now();
     $this->db->begin();
     // get extrafields so they will be clone
     foreach ($this->lines as $line) {
         $line->fetch_optionals($line->rowid);
     }
     // Load source object
     $objFrom = dol_clone($this);
     $objsoc = new Societe($this->db);
     // Change socid if needed
     if (!empty($socid) && $socid != $this->socid) {
         if ($objsoc->fetch($socid) > 0) {
             $this->socid = $objsoc->id;
             $this->cond_reglement_id = !empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0;
             $this->mode_reglement_id = !empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0;
             $this->fk_project = '';
             $this->fk_delivery_address = '';
         }
         // reset ref_client
         $this->ref_client = '';
         // TODO Change product price if multi-prices
     } else {
         $objsoc->fetch($this->socid);
     }
     $this->id = 0;
     $this->statut = 0;
     if (empty($conf->global->PROPALE_ADDON) || !is_readable(DOL_DOCUMENT_ROOT . "/core/modules/propale/" . $conf->global->PROPALE_ADDON . ".php")) {
         $this->error = 'ErrorSetupNotComplete';
         return -1;
     }
     // Clear fields
     $this->user_author = $user->id;
     $this->user_valid = '';
     $this->date = $now;
     $this->datep = $now;
     // deprecated
     $this->fin_validite = $this->date + $this->duree_validite * 24 * 3600;
     if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) {
         $this->ref_client = '';
     }
     // Set ref
     require_once DOL_DOCUMENT_ROOT . "/core/modules/propale/" . $conf->global->PROPALE_ADDON . '.php';
     $obj = $conf->global->PROPALE_ADDON;
     $modPropale = new $obj();
     $this->ref = $modPropale->getNextValue($objsoc, $this);
     // Create clone
     $result = $this->create($user);
     if ($result < 0) {
         $error++;
     } else {
         // copy internal contacts
         if ($this->copy_linked_contact($objFrom, 'internal') < 0) {
             $error++;
         } elseif ($objFrom->socid == $this->socid) {
             if ($this->copy_linked_contact($objFrom, 'external') < 0) {
                 $error++;
             }
         }
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Call trigger
         $result = $this->call_trigger('PROPAL_CLONE', $user);
         if ($result < 0) {
             $error++;
         }
         // End call triggers
     }
     unset($this->context['createfromclone']);
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
 /**
  * Overwrite magic function to solve problem of cloning object that are kept as references
  *
  * @return void
  */
 function __clone()
 {
     // Force a copy of this->lines, otherwise it will point to same object.
     if (isset($this->lines) && is_array($this->lines)) {
         $nboflines = count($this->lines);
         for ($i = 0; $i < $nboflines; $i++) {
             $this->lines[$i] = dol_clone($this->lines[$i]);
         }
     }
 }
 /**
  *	Load an object from its id and create a new one in database
  *
  *	@return		int							New id of clone
  */
 function createFromClone()
 {
     global $conf, $user, $langs, $hookmanager;
     $error = 0;
     $this->db->begin();
     // Load source object
     $objFrom = dol_clone($this);
     $this->id = 0;
     $this->statut = 0;
     // Clear fields
     $this->user_author_id = $user->id;
     $this->user_valid = '';
     $this->date_creation = '';
     $this->date_validation = '';
     $this->ref_supplier = '';
     // Create clone
     $result = $this->create($user);
     if ($result < 0) {
         $error++;
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Appel des triggers
         include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('ORDER_SUPPLIER_CLONE', $this, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // Fin appel triggers
     }
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
 /**
  *	Load an object from its id and create a new one in database
  *
  *	@param		int			$socid			Id of thirdparty
  *	@return		int							New id of clone
  */
 function createFromClone($socid = 0)
 {
     global $conf, $user, $langs, $hookmanager;
     $error = 0;
     $this->db->begin();
     // get extrafields so they will be clone
     foreach ($this->lines as $line) {
         $line->fetch_optionals($line->rowid);
     }
     // Load source object
     $objFrom = dol_clone($this);
     // Change socid if needed
     if (!empty($socid) && $socid != $this->socid) {
         $objsoc = new Societe($this->db);
         if ($objsoc->fetch($socid) > 0) {
             $this->socid = $objsoc->id;
             $this->cond_reglement_id = !empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0;
             $this->mode_reglement_id = !empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0;
             $this->fk_project = '';
             $this->fk_delivery_address = '';
         }
         // TODO Change product price if multi-prices
     }
     $this->id = 0;
     $this->statut = 0;
     // Clear fields
     $this->user_author_id = $user->id;
     $this->user_valid = '';
     $this->date_creation = '';
     $this->date_validation = '';
     $this->ref_client = '';
     // Set ref
     require_once DOL_DOCUMENT_ROOT . "/core/modules/commande/" . $conf->global->COMMANDE_ADDON . '.php';
     $obj = $conf->global->COMMANDE_ADDON;
     $modCommande = new $obj();
     $this->ref = $modCommande->getNextValue($objsoc, $this);
     // Create clone
     $result = $this->create($user);
     if ($result < 0) {
         $error++;
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Appel des triggers
         include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('ORDER_CLONE', $this, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // Fin appel triggers
     }
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
 /**
  *  Load data control
  *
  *  @param	string	$action    Type of action
  *  @param	int		$id			Id of object
  *	@return	void
  */
 function doActions(&$action, $id)
 {
     global $conf, $user, $langs;
     // Creation utilisateur depuis Adherent
     if ($action == 'confirm_create_user' && GETPOST("confirm") == 'yes') {
         // Recuperation adherent actuel
         $result = $this->object->fetch($id);
         if ($result > 0) {
             $this->db->begin();
             // Creation user
             $nuser = new User($this->db);
             $result = $nuser->create_from_member($this->object, $_POST["login"]);
             if ($result > 0) {
                 $result2 = $nuser->setPassword($user, $_POST["password"], 0, 1, 1);
                 if ($result2) {
                     $this->db->commit();
                 } else {
                     $this->db->rollback();
                 }
             } else {
                 $this->errors = $nuser->error;
                 $this->db->rollback();
             }
         } else {
             $this->errors = $this->object->errors;
         }
     }
     // Creation adherent
     if ($action == 'add') {
         $this->assign_post();
         if (!$_POST["name"]) {
             array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname") . ' / ' . $langs->transnoentities("Label")));
             $action = 'create';
         }
         if ($_POST["name"]) {
             $id = $this->object->create($user);
             if ($id > 0) {
                 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
                 exit;
             } else {
                 $this->errors = $this->object->errors;
                 $action = 'create';
             }
         }
     }
     if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
         $result = $this->object->fetch($id);
         $this->object->old_name = $_POST["old_name"];
         $this->object->old_firstname = $_POST["old_firstname"];
         $result = $this->object->delete();
         if ($result > 0) {
             header("Location: list.php");
             exit;
         } else {
             $this->errors = $this->object->errors;
         }
     }
     if ($action == 'update') {
         if ($_POST["cancel"]) {
             header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $this->object->id);
             exit;
         }
         if (empty($_POST["name"])) {
             $this->error = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name") . ' / ' . $langs->transnoentities("Label")));
             $action = 'edit';
         }
         if (empty($this->error)) {
             $this->object->fetch($_POST["adherentid"]);
             $this->object->oldcopy = dol_clone($this->object);
             $this->assign_post();
             $result = $this->object->update($_POST["adherentid"], $user);
             if ($result > 0) {
                 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $this->object->id);
                 exit;
             } else {
                 $this->errors = $this->object->errors;
                 $action = 'edit';
             }
         }
     }
 }
Пример #12
0
    /**
     * testContactUpdate
     *
     * @param	Contact		$localobject	Contact
     * @return	int
     *
     * @depends	testContactFetch
     * The depends says test is run only if previous is ok
     */
    public function testContactUpdate($localobject)
    {
    	global $conf,$user,$langs,$db;
		$conf=$this->savconf;
		$user=$this->savuser;
		$langs=$this->savlangs;
		$db=$this->savdb;

		$localobject->oldcopy=dol_clone($localobject);

		$localobject->note='New note after update';
		//$localobject->note_public='New note public after update';
		$localobject->lastname='New name';
		$localobject->firstname='New firstname';
		$localobject->address='New address';
		$localobject->zip='New zip';
		$localobject->town='New town';
    	$localobject->country_id=2;
    	//$localobject->status=0;
		$localobject->phone_pro='New tel pro';
		$localobject->phone_perso='New tel perso';
		$localobject->phone_mobile='New tel mobile';
		$localobject->fax='New fax';
		$localobject->email='*****@*****.**';
		$localobject->jabberid='New im id';
		$localobject->default_lang='es_ES';
		$result=$localobject->update($localobject->id,$user);
    	print __METHOD__." id=".$localobject->id." result=".$result."\n";
    	$this->assertLessThan($result, 0, 'Contact::update error');
		$result=$localobject->update_note($localobject->note);
    	print __METHOD__." id=".$localobject->id." result=".$result."\n";
    	$this->assertLessThan($result, 0, 'Contact::update_note error');
		//$result=$localobject->update_note_public($localobject->note_public);
    	//print __METHOD__." id=".$localobject->id." result=".$result."\n";
    	//$this->assertLessThan($result, 0);

		$newobject=new Contact($this->savdb);
    	$result=$newobject->fetch($localobject->id);
        print __METHOD__." id=".$localobject->id." result=".$result."\n";
    	$this->assertLessThan($result, 0, 'Contact::fetch error');

    	print __METHOD__." old=".$localobject->note." new=".$newobject->note."\n";
    	$this->assertEquals($localobject->note, $newobject->note);
    	//print __METHOD__." old=".$localobject->note_public." new=".$newobject->note_public."\n";
    	//$this->assertEquals($localobject->note_public, $newobject->note_public);
    	print __METHOD__." old=".$localobject->lastname." new=".$newobject->lastname."\n";
    	$this->assertEquals($localobject->lastname, $newobject->lastname);
    	print __METHOD__." old=".$localobject->firstname." new=".$newobject->firstname."\n";
    	$this->assertEquals($localobject->firstname, $newobject->firstname);
    	print __METHOD__." old=".$localobject->address." new=".$newobject->address."\n";
    	$this->assertEquals($localobject->address, $newobject->address);
    	print __METHOD__." old=".$localobject->zip." new=".$newobject->zip."\n";
    	$this->assertEquals($localobject->zip, $newobject->zip);
    	print __METHOD__." old=".$localobject->town." new=".$newobject->town."\n";
    	$this->assertEquals($localobject->town, $newobject->town);
    	print __METHOD__." old=".$localobject->country_id." new=".$newobject->country_id."\n";
    	$this->assertEquals($localobject->country_id, $newobject->country_id);
    	print __METHOD__." old=BE new=".$newobject->country_code."\n";
    	$this->assertEquals('BE', $newobject->country_code);
    	//print __METHOD__." old=".$localobject->status." new=".$newobject->status."\n";
    	//$this->assertEquals($localobject->status, $newobject->status);
    	print __METHOD__." old=".$localobject->phone_pro." new=".$newobject->phone_pro."\n";
    	$this->assertEquals($localobject->phone_pro, $newobject->phone_pro);
    	print __METHOD__." old=".$localobject->phone_pro." new=".$newobject->phone_pro."\n";
    	$this->assertEquals($localobject->phone_perso, $newobject->phone_perso);
    	print __METHOD__." old=".$localobject->phone_mobile." new=".$newobject->phone_mobile."\n";
    	$this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile);
    	print __METHOD__." old=".$localobject->fax." new=".$newobject->fax."\n";
    	$this->assertEquals($localobject->fax, $newobject->fax);
    	print __METHOD__." old=".$localobject->email." new=".$newobject->email."\n";
    	$this->assertEquals($localobject->email, $newobject->email);
    	print __METHOD__." old=".$localobject->jabberid." new=".$newobject->jabberid."\n";
    	$this->assertEquals($localobject->jabberid, $newobject->jabberid);
    	print __METHOD__." old=".$localobject->default_lang." new=".$newobject->default_lang."\n";
    	$this->assertEquals($localobject->default_lang, $newobject->default_lang);

    	return $localobject;
    }
Пример #13
0
 /**
  *		Load an object from its id and create a new one in database
  *
  *		@param		int				$socid			Id of thirdparty
  * 	 	@return		int								New id of clone
  */
 function createFromClone($socid = 0)
 {
     global $conf, $user, $langs, $hookmanager;
     $error = 0;
     $this->context['createfromclone'] = 'createfromclone';
     $this->db->begin();
     // get extrafields so they will be clone
     foreach ($this->lines as $line) {
         $line->fetch_optionals($line->rowid);
     }
     // Load source object
     $objFrom = dol_clone($this);
     // Change socid if needed
     if (!empty($socid) && $socid != $this->socid) {
         $objsoc = new Societe($this->db);
         if ($objsoc->fetch($socid) > 0) {
             $this->socid = $objsoc->id;
             $this->cond_reglement_id = !empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0;
             $this->mode_reglement_id = !empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0;
             $this->fk_project = '';
             $this->fk_delivery_address = '';
         }
         // TODO Change product price if multi-prices
     }
     $this->id = 0;
     $this->statut = 0;
     // Clear fields
     $this->date = dol_now();
     // Date of invoice is set to current date when cloning. // TODO Best is to ask date into confirm box
     $this->user_author = $user->id;
     $this->user_valid = '';
     $this->fk_facture_source = 0;
     $this->date_creation = '';
     $this->date_validation = '';
     $this->ref_client = '';
     $this->close_code = '';
     $this->close_note = '';
     $this->products = $this->lines;
     // Tant que products encore utilise
     // Loop on each line of new invoice
     foreach ($this->lines as $i => $line) {
         if (($this->lines[$i]->info_bits & 0x2) == 0x2) {
             unset($this->lines[$i]);
             unset($this->products[$i]);
             // Tant que products encore utilise
         }
     }
     // Create clone
     $result = $this->create($user);
     if ($result < 0) {
         $error++;
     } else {
         // copy internal contacts
         if ($this->copy_linked_contact($objFrom, 'internal') < 0) {
             $error++;
         } elseif ($objFrom->socid == $this->socid) {
             if ($this->copy_linked_contact($objFrom, 'external') < 0) {
                 $error++;
             }
         }
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Call trigger
         $result = $this->call_trigger('BILL_CLONE', $user);
         if ($result < 0) {
             $error++;
         }
         // End call triggers
     }
     unset($this->context['createfromclone']);
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Пример #14
0
if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
{
	require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");

	$datenaiss='';
	if (isset($_POST["naissday"]) && $_POST["naissday"]
		&& isset($_POST["naissmonth"]) && $_POST["naissmonth"]
		&& isset($_POST["naissyear"]) && $_POST["naissyear"])
	{
		$datenaiss=dol_mktime(12, 0, 0, $_POST["naissmonth"], $_POST["naissday"], $_POST["naissyear"]);
	}

	// Create new object
	if ($result > 0)
	{
		$adh->oldcopy=dol_clone($adh);

		// Change values
		$adh->civilite_id = trim($_POST["civilite_id"]);
		$adh->prenom      = trim($_POST["prenom"]);
		$adh->nom         = trim($_POST["nom"]);
		$adh->login       = trim($_POST["login"]);
		$adh->pass        = trim($_POST["pass"]);

		$adh->societe     = trim($_POST["societe"]);
        $adh->adresse     = trim($_POST["address"]);    // deprecated
		$adh->address     = trim($_POST["address"]);
        $adh->cp          = trim($_POST["zipcode"]);    // deprecated
		$adh->zip         = trim($_POST["zipcode"]);
        $adh->ville       = trim($_POST["town"]);       // deprecated
        $adh->town        = trim($_POST["town"]);
Пример #15
0
 print '<tr>';
 print '<td class="fieldrequired">' . $langs->trans("QtyMin") . '</td>';
 print '<td>';
 $quantity = GETPOST('qty') ? GETPOST('qty') : "1";
 if ($rowid) {
     print '<input type="hidden" name="qty" value="' . $product->fourn_qty . '">';
     print $product->fourn_qty;
 } else {
     print '<input class="flat" name="qty" size="5" value="' . $quantity . '">';
 }
 print '</td></tr>';
 // Vat rate
 $default_vat = '';
 // We don't have supplier, so we try to guess.
 // For this we build a fictive supplier with same properties than user but using vat)
 $mysoc2 = dol_clone($mysoc);
 $mysoc2->name = 'Fictive seller with same country';
 $mysoc2->tva_assuj = 1;
 $default_vat = get_default_tva($mysoc2, $mysoc, $product->id, 0);
 print '<tr><td class="fieldrequired">' . $langs->trans("VATRateForSupplierProduct") . '</td>';
 print '<td>';
 //print $form->load_tva('tva_tx',$product->tva_tx,$supplier,$mysoc);    // Do not use list here as it may be any vat rates for any country
 if (!empty($socid)) {
     $default_vat = get_default_tva($supplier, $mysoc, $product->id);
     if (empty($default_vat)) {
         $default_vat = $product->tva_tx;
     }
 }
 print '<input type="text" class="flat" size="5" name="tva_tx" value="' . (GETPOST("tva_tx") ? vatrate(GETPOST("tva_tx")) : ($default_vat != '' ? vatrate($default_vat) : '')) . '">';
 print '</td></tr>';
 if (!empty($conf->dynamicprices->enabled)) {
Пример #16
0
 /**
  *  Change password of a user
  *  @param     	user             		Object user of user making change
  *  @param     	password         		New password in clear text (to generate if not provided)
  *	@param		changelater				1=Change password only after clicking on confirm email
  *	@param		notrigger				1=Does not launch triggers
  *	@param		nosyncmember	        Do not synchronize linked member
  *  @return    	string           		If OK return clear password, 0 if no change, < 0 if error
  */
 function setPassword($user, $password = '', $changelater = 0, $notrigger = 0, $nosyncmember = 0)
 {
     global $conf, $langs;
     $error = 0;
     dol_syslog("User::setPassword user="******" password="******" changelater=" . $changelater . " notrigger=" . $notrigger . " nosyncmember=" . $nosyncmember, LOG_DEBUG);
     // If new password not provided, we generate one
     if (!$password) {
         include_once DOL_DOCUMENT_ROOT . '/lib/security.lib.php';
         $password = getRandomPassword('');
     }
     // Crypte avec md5
     $password_crypted = md5($password);
     // Mise a jour
     if (!$changelater) {
         if (!is_object($this->oldcopy)) {
             $this->oldcopy = dol_clone($this);
         }
         $sql = "UPDATE " . MAIN_DB_PREFIX . "user";
         $sql .= " SET pass_crypted = '" . $this->db->escape($password_crypted) . "',";
         $sql .= " pass_temp = null";
         if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
             $sql .= ", pass = null";
         } else {
             $sql .= ", pass = '******'";
         }
         $sql .= " WHERE rowid = " . $this->id;
         dol_syslog("User::setPassword sql=hidden", LOG_DEBUG);
         //dol_syslog("User::Password sql=".$sql);
         $result = $this->db->query($sql);
         if ($result) {
             if ($this->db->affected_rows($result)) {
                 $this->pass = $password;
                 $this->pass_indatabase = $password;
                 $this->pass_indatabase_crypted = $password_crypted;
                 if ($this->fk_member && !$nosyncmember) {
                     require_once DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php";
                     // This user is linked with a member, so we also update members informations
                     // if this is an update.
                     $adh = new Adherent($this->db);
                     $result = $adh->fetch($this->fk_member);
                     if ($result >= 0) {
                         $result = $adh->setPassword($user, $this->pass, 0, 1);
                         // Cryptage non gere dans module adherent
                         if ($result < 0) {
                             $this->error = $adh->error;
                             dol_syslog("User::setPassword " . $this->error, LOG_ERR);
                             $error++;
                         }
                     } else {
                         $this->error = $adh->error;
                         $error++;
                     }
                 }
                 dol_syslog("User::setPassword notrigger=" . $notrigger . " error=" . $error, LOG_DEBUG);
                 if (!$error && !$notrigger) {
                     // Appel des triggers
                     include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
                     $interface = new Interfaces($this->db);
                     $result = $interface->run_triggers('USER_NEW_PASSWORD', $this, $user, $langs, $conf);
                     if ($result < 0) {
                         $this->errors = $interface->errors;
                     }
                     // Fin appel triggers
                 }
                 return $this->pass;
             } else {
                 return 0;
             }
         } else {
             dol_print_error($this->db);
             return -1;
         }
     } else {
         // We store clear password in password temporary field.
         // After receiving confirmation link, we will crypt it and store it in pass_crypted
         $sql = "UPDATE " . MAIN_DB_PREFIX . "user";
         $sql .= " SET pass_temp = '" . $this->db->escape($password) . "'";
         $sql .= " WHERE rowid = " . $this->id;
         dol_syslog("User::setPassword sql=hidden", LOG_DEBUG);
         // No log
         $result = $this->db->query($sql);
         if ($result) {
             return $password;
         } else {
             dol_print_error($this->db);
             return -3;
         }
     }
 }
Пример #17
0
 /**
  *		Load an object from its id and create a new one in database
  *
  *		@param		int				$socid			Id of thirdparty
  *		@param		HookManager		$hookmanager	Hook manager instance
  * 	 	@return		int								New id of clone
  */
 function createFromClone($socid = 0, $hookmanager = false)
 {
     global $user, $langs, $conf;
     $error = 0;
     $now = dol_now();
     $this->db->begin();
     // Load source object
     $objFrom = dol_clone($this);
     $objsoc = new Societe($this->db);
     // Change socid if needed
     if (!empty($socid) && $socid != $this->socid) {
         if ($objsoc->fetch($socid) > 0) {
             $this->socid = $objsoc->id;
             $this->cond_reglement_id = !empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0;
             $this->mode_reglement_id = !empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0;
             $this->fk_project = '';
             $this->fk_delivery_address = '';
         }
         // TODO Change product price if multi-prices
     } else {
         $objsoc->fetch($this->socid);
     }
     $this->id = 0;
     $this->statut = 0;
     if (empty($conf->global->PROPALE_ADDON) || !is_readable(DOL_DOCUMENT_ROOT . "/core/modules/propale/" . $conf->global->PROPALE_ADDON . ".php")) {
         $this->error = 'ErrorSetupNotComplete';
         return -1;
     }
     // Clear fields
     $this->user_author = $user->id;
     $this->user_valid = '';
     $this->date = $now;
     $this->datep = $now;
     // deprecated
     $this->fin_validite = $this->date + $this->duree_validite * 24 * 3600;
     $this->ref_client = '';
     // Set ref
     require_once DOL_DOCUMENT_ROOT . "/core/modules/propale/" . $conf->global->PROPALE_ADDON . ".php";
     $obj = $conf->global->PROPALE_ADDON;
     $modPropale = new $obj();
     $this->ref = $modPropale->getNextValue($objsoc, $this);
     // Create clone
     $result = $this->create($user);
     if ($result < 0) {
         $error++;
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Appel des triggers
         include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('PROPAL_CLONE', $this, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // Fin appel triggers
     }
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
 /**
  *  Create movement in database for all subproducts
  *
  * 	@param 		User	$user			Object user
  * 	@param		int		$idProduct		Id product
  * 	@param		int		$entrepot_id	Warehouse id
  * 	@param		int		$qty			Quantity
  * 	@param		int		$type			Type
  * 	@param		int		$price			Price
  * 	@param		string	$label			Label of movement
  *  @param		string	$inventorycode	Inventory code
  * 	@return 	int     				<0 if KO, 0 if OK
  */
 function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price = 0, $label = '', $inventorycode = '')
 {
     $error = 0;
     $pids = array();
     $pqtys = array();
     $sql = "SELECT fk_product_pere, fk_product_fils, qty";
     $sql .= " FROM " . MAIN_DB_PREFIX . "product_association";
     $sql .= " WHERE fk_product_pere = " . $idProduct;
     $sql .= " AND incdec = 1";
     dol_syslog(get_class($this) . "::_createSubProduct", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $i = 0;
         while ($obj = $this->db->fetch_object($resql)) {
             $pids[$i] = $obj->fk_product_fils;
             $pqtys[$i] = $obj->qty;
             $i++;
         }
         $this->db->free($resql);
     } else {
         $error = -2;
     }
     // Create movement for each subproduct
     foreach ($pids as $key => $value) {
         $tmpmove = dol_clone($this);
         $tmpmove->_create($user, $pids[$key], $entrepot_id, $qty * $pqtys[$key], $type, 0, $label, $inventorycode);
         // This will also call _createSubProduct making this recursive
         unset($tmpmove);
     }
     return $error;
 }
Пример #19
0
                        }
                    }
                }
            }
            if ($ret >= 0 && !count($edituser->errors)) {
                $message .= '<div class="ok">' . $langs->trans("UserModified") . '</div>';
                $db->commit();
            } else {
                $db->rollback();
            }
        }
    } else {
        if ($caneditpassword) {
            $edituser = new User($db);
            $edituser->fetch($id);
            $edituser->oldcopy = dol_clone($edituser);
            $ret = $edituser->setPassword($user, $_POST["password"]);
            if ($ret < 0) {
                $message .= '<div class="error">' . $edituser->error . '</div>';
            }
        }
    }
}
// Change password with a new generated one
if (($action == 'confirm_password' && $confirm == 'yes' || $action == 'confirm_passwordsend' && $confirm == 'yes') && $caneditpassword) {
    $edituser = new User($db);
    $edituser->fetch($id);
    $newpassword = $edituser->setPassword($user, '');
    if ($newpassword < 0) {
        // Echec
        $message = '<div class="error">' . $langs->trans("ErrorFailedToSetNewPassword") . '</div>';
Пример #20
0
 /**
  *		Load an object from its id and create a new one in database
  *
  *      @param	    user	        $fuser      	Object user making action
  *		@param		int				$socid			Id of thirdparty
  * 	 	@return		int								New id of clone
  */
 function createFromClone($fuser, $socid)
 {
     global $db, $user, $langs, $conf, $hookmanager;
     $this->context['createfromclone'] = 'createfromclone';
     $error = 0;
     $now = dol_now();
     $this->db->begin();
     // Load source object
     $objFrom = dol_clone($this);
     $this->fetch_optionals();
     $this->fetch_userassigned();
     $this->id = 0;
     // Create clone
     $result = $this->add($fuser);
     if ($result < 0) {
         $error++;
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Call trigger
         $result = $this->call_trigger('ACTION_CLONE', $fuser);
         if ($result < 0) {
             $error++;
         }
         // End call triggers
     }
     unset($this->context['createfromclone']);
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Пример #21
0
 /**
  *		Load an object from its id and create a new one in database
  *
  *		@param		int				$socid			Id of thirdparty
  *		@param		HookManager		$hookmanager	Hook manager instance
  * 	 	@return		int								New id of clone
  */
 function createFromClone($socid = 0, $hookmanager = false)
 {
     global $conf, $user, $langs;
     $error = 0;
     $this->db->begin();
     // Load source object
     $objFrom = dol_clone($this);
     // Change socid if needed
     if (!empty($socid) && $socid != $this->socid) {
         $objsoc = new Societe($this->db);
         if ($objsoc->fetch($socid) > 0) {
             $this->socid = $objsoc->id;
             $this->cond_reglement_id = !empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0;
             $this->mode_reglement_id = !empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0;
             $this->fk_project = '';
             $this->fk_delivery_address = '';
         }
         // TODO Change product price if multi-prices
     }
     $this->id = 0;
     $this->statut = 0;
     // Clear fields
     $this->user_author = $user->id;
     $this->user_valid = '';
     $this->fk_facture_source = 0;
     $this->date_creation = '';
     $this->date_validation = '';
     $this->ref_client = '';
     $this->close_code = '';
     $this->close_note = '';
     $this->products = $this->lines;
     // Tant que products encore utilise
     // Loop on each line of new invoice
     foreach ($this->lines as $i => $line) {
         if (($this->lines[$i]->info_bits & 0x2) == 0x2) {
             unset($this->lines[$i]);
             unset($this->products[$i]);
             // Tant que products encore utilise
         }
     }
     // Create clone
     $result = $this->create($user);
     if ($result < 0) {
         $error++;
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Appel des triggers
         include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('BILL_CLONE', $this, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // Fin appel triggers
     }
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Пример #22
0
 /**
  *  Show menu
  *
  *	@param	string	$mode			'top', 'left', 'jmobile'
  *  @return	void
  */
 function showmenu($mode)
 {
     global $user, $conf, $langs, $dolibarr_main_db_name;
     $id = 'mainmenu';
     require_once DOL_DOCUMENT_ROOT . '/core/class/menu.class.php';
     $this->menu = new Menu();
     $res = 'ErrorBadParameterForMode';
     $noout = 0;
     if ($mode == 'jmobile') {
         $noout = 1;
     }
     if ($mode == 'top' || $mode == 'jmobile') {
         if (empty($noout)) {
             print_start_menu_array_empty();
         }
         // Home
         $showmode = 1;
         $idsel = 'home';
         $classname = 'class="tmenusel"';
         if (empty($noout)) {
             print_start_menu_entry_empty($idsel, $classname, $showmode);
         }
         if (empty($noout)) {
             print_text_menu_entry_empty($langs->trans("Home"), 1, dol_buildpath('/index.php', 1) . '?mainmenu=home&amp;leftmenu=', $id, $idsel, $classname, $this->atarget);
         }
         if (empty($noout)) {
             print_end_menu_entry_empty($showmode);
         }
         $this->menu->add(dol_buildpath('/index.php', 1), $langs->trans("Home"), 0, $showmode, $this->atarget, 'home', '');
         $showmode = 1;
         if (empty($noout)) {
             print_start_menu_entry_empty('', 'class="tmenuend"', $showmode);
         }
         if (empty($noout)) {
             print_end_menu_entry_empty($showmode);
         }
         if (empty($noout)) {
             print_end_menu_array_empty();
         }
         if ($mode == 'jmobile') {
             $this->topmenu = dol_clone($this->menu);
             unset($this->menu->liste);
         }
     }
     if ($mode == 'left' || $mode == 'jmobile') {
         // Put here left menu entries
         // ***** START *****
         $langs->load("admin");
         // Load translation file admin.lang
         $this->menu->add("/admin/index.php?leftmenu=setup", $langs->trans("Setup"), 0);
         $this->menu->add("/admin/company.php", $langs->trans("MenuCompanySetup"), 1);
         $this->menu->add("/admin/modules.php", $langs->trans("Modules"), 1);
         $this->menu->add("/admin/menus.php", $langs->trans("Menus"), 1);
         $this->menu->add("/admin/ihm.php", $langs->trans("GUISetup"), 1);
         $this->menu->add("/admin/fiscalyear.php", $langs->trans("Fiscalyear"), 1);
         $this->menu->add("/admin/boxes.php", $langs->trans("Boxes"), 1);
         $this->menu->add("/admin/delais.php", $langs->trans("Alerts"), 1);
         $this->menu->add("/admin/proxy.php?mainmenu=home", $langs->trans("Security"), 1);
         $this->menu->add("/admin/limits.php?mainmenu=home", $langs->trans("MenuLimits"), 1);
         $this->menu->add("/admin/pdf.php?mainmenu=home", $langs->trans("PDF"), 1);
         $this->menu->add("/admin/mails.php?mainmenu=home", $langs->trans("Emails"), 1);
         $this->menu->add("/admin/sms.php?mainmenu=home", $langs->trans("SMS"), 1);
         $this->menu->add("/admin/dict.php?mainmenu=home", $langs->trans("DictionarySetup"), 1);
         if (!empty($conf->accounting->enabled)) {
             $this->menu->add("/accountancy/admin/account.php", $langs->trans("Chartofaccounts"), 1);
         }
         $this->menu->add("/admin/const.php?mainmenu=home", $langs->trans("OtherSetup"), 1);
         // ***** END *****
         // do not change code after this
         if (empty($noout)) {
             $alt = 0;
             $num = count($this->menu->liste);
             for ($i = 0; $i < $num; $i++) {
                 $alt++;
                 if (empty($this->menu->liste[$i]['level'])) {
                     if ($alt % 2 == 0) {
                         print '<div class="blockvmenuimpair">' . "\n";
                     } else {
                         print '<div class="blockvmenupair">' . "\n";
                     }
                 }
                 // Place tabulation
                 $tabstring = '';
                 $tabul = $this->menu->liste[$i]['level'] - 1;
                 if ($tabul > 0) {
                     for ($j = 0; $j < $tabul; $j++) {
                         $tabstring .= '&nbsp; &nbsp;';
                     }
                 }
                 if ($this->menu->liste[$i]['level'] == 0) {
                     if ($this->menu->liste[$i]['enabled']) {
                         print '<div class="menu_titre">' . $tabstring . '<a class="vmenu" href="' . dol_buildpath($this->menu->liste[$i]['url'], 1) . '"' . ($this->menu->liste[$i]['target'] ? ' target="' . $this->menu->liste[$i]['target'] . '"' : '') . '>' . $this->menu->liste[$i]['titre'] . '</a></div>' . "\n";
                     } else {
                         print '<div class="menu_titre">' . $tabstring . '<font class="vmenudisabled">' . $this->menu->liste[$i]['titre'] . '</font></div>' . "\n";
                     }
                     print '<div class="menu_top"></div>' . "\n";
                 }
                 if ($this->menu->liste[$i]['level'] > 0) {
                     print '<div class="menu_contenu">';
                     if ($this->menu->liste[$i]['enabled']) {
                         print $tabstring . '<a class="vsmenu" href="' . dol_buildpath($this->menu->liste[$i]['url'], 1) . '">' . $this->menu->liste[$i]['titre'] . '</a><br>';
                     } else {
                         print $tabstring . '<font class="vsmenudisabled vsmenudisabledmargin">' . $this->menu->liste[$i]['titre'] . '</font><br>';
                     }
                     print '</div>' . "\n";
                 }
                 // If next is a new block or end
                 if (empty($this->menu->liste[$i + 1]['level'])) {
                     print '<div class="menu_end"></div>' . "\n";
                     print "</div>\n";
                 }
             }
         }
         if ($mode == 'jmobile') {
             $this->leftmenu = dol_clone($this->menu);
             unset($this->menu->liste);
         }
     }
     if ($mode == 'jmobile') {
         foreach ($this->topmenu->liste as $key => $val) {
             print '<ul class="ulmenu" data-role="listview" data-inset="true">';
             print '<li data-role="list-dividerxxx" class="lilevel0">';
             if ($val['enabled'] == 1) {
                 $relurl = dol_buildpath($val['url'], 1);
                 $relurl = preg_replace('/__LOGIN__/', $user->login, $relurl);
                 $relurl = preg_replace('/__USERID__/', $user->id, $relurl);
                 print '<a href="#">' . $val['titre'] . '</a>' . "\n";
                 // Search submenu fot this entry
                 $tmpmainmenu = $val['mainmenu'];
                 $tmpleftmenu = 'all';
                 //$submenu=new Menu();
                 //$res=print_left_eldy_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$submenu,1,$tmpmainmenu,$tmpleftmenu);
                 //$nexturl=dol_buildpath($submenu->liste[0]['url'],1);
                 $submenu = $this->leftmenu;
                 $canonrelurl = preg_replace('/\\?.*$/', '', $relurl);
                 $canonnexturl = preg_replace('/\\?.*$/', '', $nexturl);
                 //var_dump($canonrelurl);
                 //var_dump($canonnexturl);
                 print '<ul>';
                 if ($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('home', 'tools'))) {
                     // We add sub entry
                     print '<li data-role="list-dividerxxx"><a href="' . $relurl . '">' . $langs->trans("MainArea") . '-' . $val['titre'] . '</a></li>' . "\n";
                 }
                 foreach ($submenu->liste as $key2 => $val2) {
                     $relurl2 = dol_buildpath($val2['url'], 1);
                     $relurl2 = preg_replace('/__LOGIN__/', $user->login, $relurl2);
                     $relurl2 = preg_replace('/__USERID__/', $user->id, $relurl2);
                     //var_dump($val2);
                     print '<li' . ($val2['level'] == 0 ? ' data-role="list-dividerxxx"' : '') . '><a href="' . $relurl2 . '">' . $val2['titre'] . '</a></li>' . "\n";
                 }
                 //var_dump($submenu);
                 print '</ul>';
             }
             if ($val['enabled'] == 2) {
                 print '<font class="vsmenudisabled">' . $val['titre'] . '</font>';
             }
             print '</li>';
             print '</ul>' . "\n";
             break;
             // Only first menu entry (so home)
         }
     }
     unset($this->menu);
     return $res;
 }
Пример #23
0
}
/*
 * View
*/
llxHeader('', $langs->trans("Task"));
$form = new Form($db);
$formother = new FormOther($db);
$formfile = new FormFile($db);
if ($id > 0 || !empty($ref)) {
    if ($object->fetch($id, $ref) > 0) {
        $res = $object->fetch_optionals($object->id, $extralabels);
        $result = $projectstatic->fetch($object->fk_project);
        if (!empty($projectstatic->socid)) {
            $projectstatic->fetch_thirdparty();
        }
        $object->project = dol_clone($projectstatic);
        $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
        if (!empty($withproject)) {
            // Tabs for project
            $tab = 'tasks';
            $head = project_prepare_head($projectstatic);
            dol_fiche_head($head, $tab, $langs->trans("Project"), 0, $projectstatic->public ? 'projectpub' : 'project');
            $param = $mode == 'mine' ? '&mode=mine' : '';
            print '<table class="border" width="100%">';
            // Ref
            print '<tr><td width="30%">';
            print $langs->trans("Ref");
            print '</td><td>';
            // Define a complementary filter for search of next/prev ref.
            if (!$user->rights->projet->all->lire) {
                $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, $mine, 0);
 /**
  *      Function called when a Dolibarrr business event is done.
  *      All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  *
  *      @param	string		$action		Event action code
  *      @param  Object		$object     Object
  *      @param  User		$user       Object user
  *      @param  Translate	$langs      Object langs
  *      @param  conf		$conf       Object conf
  *      @return int         			<0 if KO, 0 if no triggered ran, >0 if OK
  */
 function run_trigger($action, $object, $user, $langs, $conf)
 {
     if (empty($conf->ldap->enabled)) {
         return 0;
     }
     // Module not active, we do nothing
     if (!function_exists('ldap_connect')) {
         dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING);
         return 0;
     }
     // Users
     if ($action == 'USER_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->add($dn, $info, $user);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'USER_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             if (empty($object->oldcopy) || !is_object($object->oldcopy)) {
                 dol_syslog("Trigger " . $action . " was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
                 $object->oldcopy = dol_clone($object);
             }
             $oldinfo = $object->oldcopy->_load_ldap_info();
             $olddn = $object->oldcopy->_load_ldap_dn($oldinfo);
             // Verify if entry exist
             $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1);
             $search = "(" . $object->oldcopy->_load_ldap_dn($oldinfo, 2) . ")";
             $records = $ldap->search($container, $search);
             if (count($records) && $records['count'] == 0) {
                 $olddn = '';
             }
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->update($dn, $info, $user, $olddn);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'USER_NEW_PASSWORD') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             if (empty($object->oldcopy) || !is_object($object->oldcopy)) {
                 dol_syslog("Trigger " . $action . " was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
                 $object->oldcopy = dol_clone($object);
             }
             $oldinfo = $object->oldcopy->_load_ldap_info();
             $olddn = $object->oldcopy->_load_ldap_dn($oldinfo);
             // Verify if entry exist
             $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1);
             $search = "(" . $object->oldcopy->_load_ldap_dn($oldinfo, 2) . ")";
             $records = $ldap->search($container, $search);
             if (count($records) && $records['count'] == 0) {
                 $olddn = '';
             }
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->update($dn, $info, $user, $olddn);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'USER_ENABLEDISABLE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
     } elseif ($action == 'USER_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->delete($dn, $info, $user);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'USER_SETINGROUP') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             // Must edit $object->newgroupid
             $usergroup = new UserGroup($this->db);
             if ($object->newgroupid > 0) {
                 $usergroup->fetch($object->newgroupid);
                 $oldinfo = $usergroup->_load_ldap_info();
                 $olddn = $usergroup->_load_ldap_dn($oldinfo);
                 // Verify if entry exist
                 $container = $usergroup->_load_ldap_dn($oldinfo, 1);
                 $search = "(" . $usergroup->_load_ldap_dn($oldinfo, 2) . ")";
                 $records = $ldap->search($container, $search);
                 if (count($records) && $records['count'] == 0) {
                     $olddn = '';
                 }
                 $info = $usergroup->_load_ldap_info();
                 // Contains all members, included the new one (insert already done before trigger call)
                 $dn = $usergroup->_load_ldap_dn($info);
                 $result = $ldap->update($dn, $info, $user, $olddn);
                 if ($result < 0) {
                     $this->error = "ErrorLDAP " . $ldap->error;
                 }
             }
             return $result;
         }
     } elseif ($action == 'USER_REMOVEFROMGROUP') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             // Must edit $object->newgroupid
             $usergroup = new UserGroup($this->db);
             if ($object->oldgroupid > 0) {
                 $usergroup->fetch($object->oldgroupid);
                 $oldinfo = $usergroup->_load_ldap_info();
                 $olddn = $usergroup->_load_ldap_dn($oldinfo);
                 // Verify if entry exist
                 $container = $usergroup->_load_ldap_dn($oldinfo, 1);
                 $search = "(" . $usergroup->_load_ldap_dn($oldinfo, 2) . ")";
                 $records = $ldap->search($container, $search);
                 if (count($records) && $records['count'] == 0) {
                     $olddn = '';
                 }
                 $info = $usergroup->_load_ldap_info();
                 // Contains all members, included the new one (insert already done before trigger call)
                 $dn = $usergroup->_load_ldap_dn($info);
                 $result = $ldap->update($dn, $info, $user, $olddn);
                 if ($result < 0) {
                     $this->error = "ErrorLDAP " . $ldap->error;
                 }
             }
             return $result;
         }
     } elseif ($action == 'GROUP_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             // Get a gid number for objectclass PosixGroup
             if (in_array('posixGroup', $info['objectclass'])) {
                 $info['gidNumber'] = $ldap->getNextGroupGid();
             }
             $result = $ldap->add($dn, $info, $user);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'GROUP_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             if (empty($object->oldcopy) || !is_object($object->oldcopy)) {
                 dol_syslog("Trigger " . $action . " was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
                 $object->oldcopy = dol_clone($object);
             }
             $oldinfo = $object->oldcopy->_load_ldap_info();
             $olddn = $object->oldcopy->_load_ldap_dn($oldinfo);
             // Verify if entry exist
             $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1);
             $search = "(" . $object->oldcopy->_load_ldap_dn($oldinfo, 2) . ")";
             $records = $ldap->search($container, $search);
             if (count($records) && $records['count'] == 0) {
                 $olddn = '';
             }
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->update($dn, $info, $user, $olddn);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'GROUP_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') {
             $ldap = new Ldap();
             $ldap->connect_bind();
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->delete($dn, $info, $user);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'CONTACT_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) {
             $ldap = new Ldap();
             $ldap->connect_bind();
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->add($dn, $info, $user);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'CONTACT_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) {
             $ldap = new Ldap();
             $ldap->connect_bind();
             if (empty($object->oldcopy) || !is_object($object->oldcopy)) {
                 dol_syslog("Trigger " . $action . " was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
                 $object->oldcopy = dol_clone($object);
             }
             $oldinfo = $object->oldcopy->_load_ldap_info();
             $olddn = $object->oldcopy->_load_ldap_dn($oldinfo);
             // Verify if entry exist
             $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1);
             $search = "(" . $object->oldcopy->_load_ldap_dn($oldinfo, 2) . ")";
             $records = $ldap->search($container, $search);
             if (count($records) && $records['count'] == 0) {
                 $olddn = '';
             }
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->update($dn, $info, $user, $olddn);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'CONTACT_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) {
             $ldap = new Ldap();
             $ldap->connect_bind();
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->delete($dn, $info, $user);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'MEMBER_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_MEMBER_ACTIVE)) {
             $ldap = new Ldap();
             $ldap->connect_bind();
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->add($dn, $info, $user);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'MEMBER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_MEMBER_ACTIVE)) {
             // If status field is setup to be synchronized
             if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) {
                 $ldap = new Ldap();
                 $ldap->connect_bind();
                 $info = $object->_load_ldap_info();
                 $dn = $object->_load_ldap_dn($info);
                 $olddn = $dn;
                 // We know olddn=dn as we change only status
                 $result = $ldap->update($dn, $info, $user, $olddn);
                 if ($result < 0) {
                     $this->error = "ErrorLDAP " . $ldap->error;
                 }
                 return $result;
             }
         }
     } elseif ($action == 'MEMBER_SUBSCRIPTION') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_MEMBER_ACTIVE)) {
             // If subscriptions fields are setup to be synchronized
             if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE || $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) {
                 $ldap = new Ldap();
                 $ldap->connect_bind();
                 $info = $object->_load_ldap_info();
                 $dn = $object->_load_ldap_dn($info);
                 $olddn = $dn;
                 // We know olddn=dn as we change only subscriptions
                 $result = $ldap->update($dn, $info, $user, $olddn);
                 if ($result < 0) {
                     $this->error = "ErrorLDAP " . $ldap->error;
                 }
                 return $result;
             }
         }
     } elseif ($action == 'MEMBER_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_MEMBER_ACTIVE)) {
             $ldap = new Ldap();
             $ldap->connect_bind();
             if (empty($object->oldcopy) || !is_object($object->oldcopy)) {
                 dol_syslog("Trigger " . $action . " was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
                 $object->oldcopy = dol_clone($object);
             }
             $oldinfo = $object->oldcopy->_load_ldap_info();
             $olddn = $object->oldcopy->_load_ldap_dn($oldinfo);
             // Verify if entry exist
             $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1);
             $search = "(" . $object->oldcopy->_load_ldap_dn($oldinfo, 2) . ")";
             $records = $ldap->search($container, $search);
             if (count($records) && $records['count'] == 0) {
                 $olddn = '';
             }
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->update($dn, $info, $user, $olddn);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     } elseif ($action == 'MEMBER_NEW_PASSWORD') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_MEMBER_ACTIVE)) {
             // If password field is setup to be synchronized
             if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) {
                 $ldap = new Ldap();
                 $ldap->connect_bind();
                 $info = $object->_load_ldap_info();
                 $dn = $object->_load_ldap_dn($info);
                 $olddn = $dn;
                 // We know olddn=dn as we change only password
                 $result = $ldap->update($dn, $info, $user, $olddn);
                 if ($result < 0) {
                     $this->error = "ErrorLDAP " . $ldap->error;
                 }
                 return $result;
             }
         }
     } elseif ($action == 'MEMBER_RESILIATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_MEMBER_ACTIVE)) {
             // If status field is setup to be synchronized
             if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) {
                 $ldap = new Ldap();
                 $ldap->connect_bind();
                 $info = $object->_load_ldap_info();
                 $dn = $object->_load_ldap_dn($info);
                 $olddn = $dn;
                 // We know olddn=dn as we change only status
                 $result = $ldap->update($dn, $info, $user, $olddn);
                 if ($result < 0) {
                     $this->error = "ErrorLDAP " . $ldap->error;
                 }
                 return $result;
             }
         }
     } elseif ($action == 'MEMBER_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         if (!empty($conf->global->LDAP_MEMBER_ACTIVE)) {
             $ldap = new Ldap();
             $ldap->connect_bind();
             $info = $object->_load_ldap_info();
             $dn = $object->_load_ldap_dn($info);
             $result = $ldap->delete($dn, $info, $user);
             if ($result < 0) {
                 $this->error = "ErrorLDAP " . $ldap->error;
             }
             return $result;
         }
     }
     // If not found
     /*
             else
             {
                 dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
     			return -1;
             }
     */
     return 0;
 }
Пример #25
0
    if (GETPOST('getsuppliercode'))
    {
        // We defined value code_fournisseur
        $_POST["code_fournisseur"]="Acompleter";
    }

    // Add new third party
    if ((! GETPOST('getcustomercode') && ! GETPOST('getsuppliercode'))
    && ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
    {
        require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");

        if ($action == 'update')
        {
        	$ret=$object->load($socid);
        	$object->oldcopy=dol_clone($object);
        }
		else $object->canvas=$canvas;

        if (GETPOST("private") == 1)
        {
            $object->particulier       = GETPOST("private");

            $object->name              = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
            $object->civilite_id       = $_POST["civilite_id"];
            // Add non official properties
            $object->name_bis          = $_POST["nom"];
            $object->firstname         = $_POST["prenom"];
        }
        else
        {
 /**
  *		Load an object from its id and create a new one in database
  *
  *		@param		int				$socid			Id of thirdparty
  * 	 	@return		int								New id of clone
  */
 function createFromClone($socid = 0)
 {
     global $user, $langs, $conf, $hookmanager;
     $error = 0;
     $now = dol_now();
     $this->db->begin();
     // get extrafields so they will be clone
     foreach ($this->lines as $line) {
         $line->fetch_optionals($line->rowid);
     }
     // Load source object
     $objFrom = dol_clone($this);
     $objsoc = new Societe($this->db);
     // Change socid if needed
     if (!empty($socid) && $socid != $this->socid) {
         if ($objsoc->fetch($socid) > 0) {
             $this->socid = $objsoc->id;
             $this->cond_reglement_id = !empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0;
             $this->mode_reglement_id = !empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0;
             $this->fk_project = '';
         }
         // TODO Change product price if multi-prices
     } else {
         $objsoc->fetch($this->socid);
     }
     $this->id = 0;
     $this->statut = 0;
     if (empty($conf->global->ASKPRICESUPPLIER_ADDON) || !is_readable(DOL_DOCUMENT_ROOT . "/core/modules/askpricesupplier/" . $conf->global->ASKPRICESUPPLIER_ADDON . ".php")) {
         $this->error = 'ErrorSetupNotComplete';
         return -1;
     }
     // Clear fields
     $this->user_author = $user->id;
     $this->user_valid = '';
     $this->date = $now;
     // Set ref
     require_once DOL_DOCUMENT_ROOT . "/core/modules/askpricesupplier/" . $conf->global->ASKPRICESUPPLIER_ADDON . '.php';
     $obj = $conf->global->ASKPRICESUPPLIER_ADDON;
     $modAskPriceSupplier = new $obj();
     $this->ref = $modAskPriceSupplier->getNextValue($objsoc, $this);
     // Create clone
     $result = $this->create($user);
     if ($result < 0) {
         $error++;
     }
     if (!$error) {
         // Hook of thirdparty module
         if (is_object($hookmanager)) {
             $parameters = array('objFrom' => $objFrom);
             $action = '';
             $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if ($reshook < 0) {
                 $error++;
             }
         }
         // Call trigger
         $result = $this->call_trigger('ASKPRICESUPPLIER_CLONE', $user);
         if ($result < 0) {
             $error++;
         }
         // End call triggers
     }
     // End
     if (!$error) {
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }