/** * {@inheritDoc} */ public function storeAccessToken($service, TokenInterface $token) { //var_dump("storeAccessToken"); //var_dump($token); dol_syslog("storeAccessToken"); $serializedToken = serialize($token); $this->tokens[$service] = $token; if (!is_array($this->tokens)) { $this->tokens = array(); } $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "oauth_token"; $sql .= " WHERE service='" . $service . "' AND entity=1"; $resql = $this->db->query($sql); if (!$resql) { dol_print_error($this->db); } $obj = $this->db->fetch_array($resql); if ($obj) { // update $sql = "UPDATE " . MAIN_DB_PREFIX . "oauth_token"; $sql .= " SET token='" . $this->db->escape($serializedToken) . "'"; $sql .= " WHERE rowid='" . $obj['rowid'] . "'"; $resql = $this->db->query($sql); } else { // save $sql = "INSERT INTO " . MAIN_DB_PREFIX . "oauth_token (service, token, entity)"; $sql .= " VALUES ('" . $service . "', '" . $this->db->escape($serializedToken) . "', 1)"; $resql = $this->db->query($sql); } //print $sql; // allow chaining return $this; }
/** * Return list of way to order * * @param string $selected Id of preselected input method * @param string $htmlname Name of HTML select list * @param int $addempty 0=liste sans valeur nulle, 1=ajoute valeur inconnue * @return array Tableau des sources de commandes */ function select_methodes_commande($selected = '', $htmlname = 'source_id', $addempty = 0) { global $conf, $langs; $listemethodes = array(); require_once DOL_DOCUMENT_ROOT . "/core/class/html.form.class.php"; $form = new Form($this->db); $sql = "SELECT rowid, code, libelle as label"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_input_method"; $sql .= " WHERE active = 1"; dol_syslog(get_class($this) . "::select_methodes_commande sql=" . $sql); $resql = $this->db->query($sql); if ($resql) { $i = 0; $num = $this->db->num_rows($resql); while ($i < $num) { $obj = $this->db->fetch_object($resql); $listemethodes[$obj->rowid] = $langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : $obj->label; $i++; } } else { dol_print_error($this->db); return -1; } print $form->selectarray($htmlname, $listemethodes, $selected, $addempty); return 1; }
/** * Insert accountancy system name into database * * @param User $user making insert * @return int if KO, Id of line if OK */ function create($user) { $now = dol_now(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_system"; $sql .= " (date_creation, fk_user_author, numero, label)"; $sql .= " VALUES (" . $this->db->idate($now) . "," . $user->id . ",'" . $this->numero . "','" . $this->label . "')"; dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_system"); if ($id > 0) { $this->rowid = $id; $result = $this->rowid; } else { $result = -2; $this->error = "AccountancySystem::Create Erreur {$result}"; dol_syslog($this->error, LOG_ERR); } } else { $result = -1; $this->error = "AccountancySystem::Create Erreur {$result}"; dol_syslog($this->error, LOG_ERR); } return $result; }
/** * Charge en memoire et renvoie la liste des modeles actifs * * @param DoliDB $db Database handler * @param integer $maxfilenamelength Max length of value to show * @return array List of templates */ function liste_modeles($db, $maxfilenamelength = 0) { dol_syslog(get_class($this) . "::liste_modeles"); $dir = DOL_DOCUMENT_ROOT . "/core/modules/import/"; $handle = opendir($dir); // Recherche des fichiers drivers imports disponibles $var = True; $i = 0; if (is_resource($handle)) { while (($file = readdir($handle)) !== false) { if (preg_match("/^import_(.*)\\.modules\\.php/i", $file, $reg)) { $moduleid = $reg[1]; // Loading Class $file = $dir . "/import_" . $moduleid . ".modules.php"; $classname = "Import" . ucfirst($moduleid); require_once $file; $module = new $classname($db, ''); // Picto $this->picto[$module->id] = $module->picto; // Driver properties $this->_driverlabel[$module->id] = $module->getDriverLabel(''); $this->_driverdesc[$module->id] = $module->getDriverDesc(''); $this->_driverversion[$module->id] = $module->getDriverVersion(''); // If use an external lib $this->_liblabel[$module->id] = $module->getLibLabel(''); $this->_libversion[$module->id] = $module->getLibVersion(''); $i++; } } } return array_keys($this->_driverlabel); }
/** * Load into memory list of available export format * * @param DoliDB $db Database handler * @param integer $maxfilenamelength Max length of value to show * @return array List of templates (same content than array this->driverlabel) */ function liste_modeles($db, $maxfilenamelength = 0) { dol_syslog(get_class($this) . "::liste_modeles"); $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; $handle = opendir($dir); // Recherche des fichiers drivers exports disponibles $var = True; $i = 0; if (is_resource($handle)) { while (($file = readdir($handle)) !== false) { if (preg_match("/^export_(.*)\\.modules\\.php\$/i", $file, $reg)) { $moduleid = $reg[1]; // Chargement de la classe $file = $dir . "/export_" . $moduleid . ".modules.php"; $classname = "Export" . ucfirst($moduleid); require_once $file; $module = new $classname($db); // Picto $this->picto[$module->id] = $module->picto; // Driver properties $this->driverlabel[$module->id] = $module->getDriverLabel() . (empty($module->disabled) ? '' : ' __(Disabled)__'); // '__(Disabled)__' is a key $this->driverdesc[$module->id] = $module->getDriverDesc(); $this->driverversion[$module->id] = $module->getDriverVersion(); // If use an external lib $this->liblabel[$module->id] = $module->getLibLabel(); $this->libversion[$module->id] = $module->getLibVersion(); $i++; } } closedir($handle); } asort($this->driverlabel); return $this->driverlabel; }
/** * Returns the text label from units dictionnary * * @param string $type Label type (long or short) * @return string|int <0 if ko, label if ok */ public function getLabelOfUnit($type = 'long') { global $langs; if (!$this->fk_unit) { return ''; } $langs->load('products'); $this->db->begin(); $label_type = 'label'; if ($type == 'short') { $label_type = 'short_label'; } $sql = 'select ' . $label_type . ' from ' . MAIN_DB_PREFIX . 'c_units where rowid=' . $this->fk_unit; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { $res = $this->db->fetch_array($resql); $label = $res[$label_type]; $this->db->free($resql); return $label; } else { $this->error = $this->db->error() . ' sql=' . $sql; dol_syslog(get_class($this) . "::getLabelOfUnit Error " . $this->error, LOG_ERR); return -1; } }
/** * Check validity of user/password/entity * If test is ko, reason must be filled into $_SESSION["dol_loginmesg"] * * @param string $usertotest Login * @param string $passwordtotest Password * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) * @return string Login if OK, '' if KO */ function check_user_password_dolibarr($usertotest, $passwordtotest, $entitytotest = 1) { global $db, $conf, $langs; global $mc; dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=" . $usertotest); $login = ''; if (!empty($usertotest)) { try { $host = substr($conf->couchdb->host, 7); $client = new couchClient('http://' . $usertotest . ':' . $passwordtotest . '@' . $host . ':' . $conf->couchdb->port . '/', $conf->couchdb->name, array("cookie_auth" => TRUE)); $_SESSION['couchdb'] = $client->getSessionCookie(); } catch (Exception $e) { print $e->getMessage(); exit; } if (strlen($_SESSION['couchdb']) < 15) { sleep(1); $langs->load('main'); $langs->load('errors'); $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword"); } else { $login = $usertotest; } } return $login; }
/** * Recupere l'objet prelevement * * @param int $rowid id de la facture a recuperer * @return void|int */ function fetch($rowid) { global $conf; $result = 0; $sql = "SELECT pl.rowid, pl.amount, p.ref, p.rowid as bon_rowid"; $sql .= ", pl.statut, pl.fk_soc"; $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_lignes as pl"; $sql .= ", " . MAIN_DB_PREFIX . "prelevement_bons as p"; $sql .= " WHERE pl.rowid=" . $rowid; $sql .= " AND p.rowid = pl.fk_prelevement_bons"; $sql .= " AND p.entity = " . $conf->entity; $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; $this->amount = $obj->amount; $this->socid = $obj->fk_soc; $this->statut = $obj->statut; $this->bon_ref = $obj->ref; $this->bon_rowid = $obj->bon_rowid; } else { $result++; dol_syslog("LignePrelevement::Fetch rowid={$rowid} numrows=0"); } $this->db->free($resql); } else { $result++; dol_syslog("LignePrelevement::Fetch rowid={$rowid}"); dol_syslog($this->db->error()); } return $result; }
/** * Return combo list of differents status of a proposal * Values are id of table c_propalst * * @param string $selected Preselected value * @param int $short Use short labels * @param int $excludedraft 0=All status, 1=Exclude draft status * @param int $showempty 1=Add empty line * @param string $mode 'customer', 'supplier' * @return void */ function selectProposalStatus($selected = '', $short = 0, $excludedraft = 0, $showempty = 1, $mode = 'customer') { global $langs; $prefix = ''; $listofstatus = array(); if ($mode == 'supplier') { $prefix = 'SupplierProposalStatus'; $langs->load("supplier_proposal"); $listofstatus = array(0 => array('code' => 'PR_DRAFT'), 1 => array('code' => 'PR_OPEN'), 2 => array('code' => 'PR_SIGNED'), 3 => array('code' => 'PR_NOTSIGNED'), 4 => array('code' => 'PR_CLOSED')); } else { $prefix = "PropalStatus"; $sql = "SELECT id, code, label, active FROM " . MAIN_DB_PREFIX . "c_propalst"; $sql .= " WHERE active = 1"; dol_syslog(get_class($this) . "::selectProposalStatus", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; if ($num) { while ($i < $num) { $obj = $this->db->fetch_object($resql); $listofstatus[$obj->id] = array('id' => $obj->id, 'code' => $obj->code, 'label' => $obj->label); $i++; } } } else { dol_print_error($this->db); } } print '<select class="flat" name="propal_statut">'; if ($showempty) { print '<option value=""> </option>'; } foreach ($listofstatus as $key => $obj) { if ($excludedraft) { if ($obj['code'] == 'Draft' || $obj['code'] == 'PR_DRAFT') { $i++; continue; } } if ($selected == $obj['id']) { print '<option value="' . $obj['id'] . '" selected>'; } else { print '<option value="' . $obj['id'] . '">'; } $key = $obj['code']; if ($langs->trans($prefix . "PropalStatus" . $key . ($short ? 'Short' : '')) != $prefix . "PropalStatus" . $key . ($short ? 'Short' : '')) { print $langs->trans($prefix . "PropalStatus" . $key . ($short ? 'Short' : '')); } else { $conv_to_new_code = array('PR_DRAFT' => 'Draft', 'PR_OPEN' => 'Opened', 'PR_CLOSED' => 'Closed', 'PR_SIGNED' => 'Signed', 'PR_NOTSIGNED' => 'NotSigned', 'PR_FAC' => 'Billed'); if (!empty($conv_to_new_code[$obj['code']])) { $key = $conv_to_new_code[$obj['code']]; } print $langs->trans($prefix . $key . ($short ? 'Short' : '')) != $prefix . $key . ($short ? 'Short' : '') ? $langs->trans($prefix . $key . ($short ? 'Short' : '')) : $obj['label']; } print '</option>'; $i++; } print '</select>'; }
/** * Create an object to build an HTML area to edit a large string content * * @param string $htmlname HTML name of WYSIWIG field * @param string $content Content of WYSIWIG field * @param int $width Width in pixel of edit area (auto by default) * @param int $height Height in pixel of edit area (200px by default) * @param string $toolbarname Name of bar set to use ('Full', 'dolibarr_notes', 'dolibarr_details', 'dolibarr_mailings') * @param string $toolbarlocation Where bar is stored : * 'In' each window has its own toolbar * 'Out:name' share toolbar into the div called 'name' * @param boolean $toolbarstartexpanded Bar is visible or not at start * @param int $uselocalbrowser Enabled to add links to local object with local browser. If false, only external images can be added in content. * @param int $okforextendededitor True=Allow usage of extended editor tool (like fckeditor) * @param int $rows Size of rows for textarea tool * @param int $cols Size of cols for textarea tool */ function DolEditor($htmlname, $content, $width = '', $height = 200, $toolbarname = 'Basic', $toolbarlocation = 'In', $toolbarstartexpanded = false, $uselocalbrowser = true, $okforextendededitor = true, $rows = 0, $cols = 0) { global $conf, $langs; dol_syslog(get_class($this) . "::DolEditor htmlname=" . $htmlname . " toolbarname=" . $toolbarname); if (!$rows) { $rows = round($height / 20); } if (!$cols) { $cols = $width ? round($width / 6) : 80; } // Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor') $defaulteditor = 'ckeditor'; $this->tool = empty($conf->global->FCKEDITOR_EDITORNAME) ? $defaulteditor : $conf->global->FCKEDITOR_EDITORNAME; $this->uselocalbrowser = $uselocalbrowser; // Define content and some properties if ($this->tool == 'ckeditor') { $content = dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML. } if ($this->tool == 'fckeditor') { require_once DOL_DOCUMENT_ROOT . "/includes/fckeditor/fckeditor.php"; $content = dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML. $this->editor = new FCKeditor($htmlname); $this->editor->BasePath = DOL_URL_ROOT . '/includes/fckeditor/'; $this->editor->Value = $content; $this->editor->Height = $height; if (!empty($width)) { $this->editor->Width = $width; } $this->editor->ToolbarSet = $toolbarname; $this->editor->Config['AutoDetectLanguage'] = 'true'; $this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In'; $this->editor->Config['ToolbarStartExpanded'] = $toolbarstartexpanded; // Rem: Le forcage de ces 2 parametres ne semble pas fonctionner. // Dolibarr utilise toujours liens avec modulepart='fckeditor' quelque soit modulepart. // Ou se trouve donc cette valeur /viewimage.php?modulepart=fckeditor&file=' ? $modulepart = 'fckeditor'; $this->editor->Config['UserFilesPath'] = '/viewimage.php?modulepart=' . $modulepart . '&file='; $this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT . '/' . $modulepart . '/'; $this->editor->Config['LinkBrowser'] = $uselocalbrowser ? 'true' : 'false'; $this->editor->Config['ImageBrowser'] = $uselocalbrowser ? 'true' : 'false'; if (file_exists(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/fckeditor/fckconfig.js')) { $this->editor->Config['CustomConfigurationsPath'] = DOL_URL_ROOT . '/theme/' . $conf->theme . '/fckeditor/fckconfig.js'; $this->editor->Config['SkinPath'] = DOL_URL_ROOT . '/theme/' . $conf->theme . '/fckeditor/'; } } // Define some properties if (in_array($this->tool, array('textarea', 'ckeditor'))) { $this->content = $content; $this->htmlname = $htmlname; $this->toolbarname = $toolbarname; $this->toolbarstartexpanded = $toolbarstartexpanded; $this->rows = max(ROWS_3, $rows); $this->cols = max(40, $cols); $this->height = $height; $this->width = $width; } }
/** * \brief Check user and password * \param usertotest Login * \param passwordtotest Password * \return string Login if ok, '' if ko. */ function check_user_password_empty($usertotest,$passwordtotest) { dol_syslog("functions_empty::check_user_password_empty usertotest=".$usertotest); $login=''; return $login; }
/** * Load data for box to show them later * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 10) { global $user, $langs, $db, $conf; $this->max = $max; include_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php'; $ficheinterstatic = new Fichinter($db); $this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter", $max)); if ($user->rights->ficheinter->lire) { $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut,"; $sql .= " f.datec,"; $sql .= " f.date_valid as datev,"; $sql .= " f.tms as datem,"; $sql .= " s.nom, s.rowid as socid, s.client"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; if (!$user->rights->societe->client->voir) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= ", " . MAIN_DB_PREFIX . "fichinter as f"; $sql .= " WHERE f.fk_soc = s.rowid "; $sql .= " AND f.entity = " . $conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id; } $sql .= " ORDER BY f.tms DESC"; $sql .= $db->plimit($max, 0); dol_syslog(get_class($this) . '::loadBox sql=' . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $now = dol_now(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($resql); $datec = $db->jdate($objp->datec); $ficheinterstatic->statut = $objp->fk_statut; $ficheinterstatic->id = $objp->rowid; $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/fichinter/fiche.php?id=" . $objp->rowid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->ref ? $objp->ref : $objp->rowid, 'url' => DOL_URL_ROOT . "/fichinter/fiche.php?id=" . $objp->rowid); $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => dol_trunc($objp->nom, 40), 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => dol_print_date($datec, 'day')); $this->info_box_contents[$i][5] = array('td' => 'align="right" class="nowrap"', 'text' => $ficheinterstatic->getLibStatut(6), 'asis' => 1); $i++; } if ($num == 0) { $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoRecordedInterventions")); } $db->free($resql); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Check validity of user/password/entity * If test is ko, reason must be filled into $_SESSION["dol_loginmesg"] * * @param string $usertotest Login * @param string $passwordtotest Password * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) * @return string Login if OK, '' if KO */ function check_user_password_http($usertotest, $passwordtotest, $entitytotest) { dol_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=" . (empty($_SERVER["REMOTE_USER"]) ? '' : $_SERVER["REMOTE_USER"])); $login = ''; if (!empty($_SERVER["REMOTE_USER"])) { $login = $_SERVER["REMOTE_USER"]; } return $login; }
/** * \brief Load data into info_box_contents array to show array later. * \param $max Maximum number of records to load */ function loadBox($max = 5) { global $user, $langs, $db, $conf; $this->max = $max; $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts")); if ($user->rights->banque->lire) { $sql = "SELECT rowid, ref, label, bank, number, courant, clos, rappro, url,"; $sql .= " code_banque, code_guichet, cle_rib, bic, iban_prefix,"; $sql .= " domiciliation, proprio, adresse_proprio,"; $sql .= " account_number, currency_code,"; $sql .= " min_allowed, min_desired, comment"; $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account"; $sql .= " WHERE entity = " . $conf->entity; //feito para o kurt, um sql diferente se o usuário for o CBA (id 7), ele só pode ver a conta mineirao (id 3) if ($user->id == 7) { $sql .= " AND rowid = 3"; } $sql .= " AND clos = 0"; $sql .= " AND courant = 1"; $sql .= " ORDER BY label"; $sql .= $db->plimit($max, 0); dol_syslog("Box_comptes::loadBox sql=" . $sql); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; $solde_total = 0; $listofcurrencies = array(); $account_static = new Account($db); while ($i < $num) { $objp = $db->fetch_object($result); $account_static->id = $objp->rowid; $solde = $account_static->solde(0); $solde_total += $solde; $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/compta/bank/account.php?account=" . $objp->rowid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->label, 'url' => DOL_URL_ROOT . "/compta/bank/account.php?account=" . $objp->rowid); $this->info_box_contents[$i][2] = array('td' => 'align="left"', 'text' => $objp->number); $this->info_box_contents[$i][3] = array('td' => 'align="right"', 'text' => price($solde) . ' ' . $langs->trans("Currency" . $objp->currency_code)); $listofcurrencies[$objp->currency_code] = 1; $i++; } // Total if (sizeof($listofcurrencies) <= 1) { $this->info_box_contents[$i][0] = array('tr' => 'class="liste_total"', 'td' => 'align="right" class="liste_total"', 'text' => $langs->trans('Total')); $this->info_box_contents[$i][1] = array('td' => 'align="right" class="liste_total"', 'text' => ' '); $this->info_box_contents[$i][2] = array('td' => 'align="right" class="liste_total"', 'text' => ' '); $totalamount = price($solde_total) . ' ' . $langs->trans("Currency" . $conf->monnaie); $this->info_box_contents[$i][3] = array('td' => 'align="right" class="liste_total"', 'text' => $totalamount); } } else { dol_print_error($db); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Load data for box to show them later * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $user, $langs, $db, $conf; $langs->load("boxes"); $this->max = $max; include_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; $thirdpartystatic = new Societe($db); $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers", $max)); if ($user->rights->societe->lire) { $sql = "SELECT s.nom, s.rowid as socid, s.datec, s.tms, s.status"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE s.client IN (1, 3)"; $sql .= " AND s.entity IN (" . getEntity('societe', 1) . ")"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = {$user->societe_id}"; } $sql .= " ORDER BY s.tms DESC"; $sql .= $db->plimit($max, 0); dol_syslog(get_class($this) . "::loadBox sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) { $url = DOL_URL_ROOT . "/comm/fiche.php?socid="; } else { $url = DOL_URL_ROOT . "/societe/soc.php?socid="; } $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); $datec = $db->jdate($objp->datec); $datem = $db->jdate($objp->tms); $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => $url . $objp->socid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->nom, 'url' => $url . $objp->socid); $this->info_box_contents[$i][2] = array('td' => 'align="right"', 'text' => dol_print_date($datem, "day")); $this->info_box_contents[$i][3] = array('td' => 'align="right" width="18"', 'text' => $thirdpartystatic->LibStatut($objp->status, 3)); $i++; } if ($num == 0) { $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoRecordedCustomers")); } $db->free($result); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('align' => 'left', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Check validity of user/password/entity * If test is ko, reason must be filled into $_SESSION["dol_loginmesg"] * * @param string $usertotest Login * @param string $passwordtotest Password * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) * @return string Login if OK, '' if KO */ function check_user_password_otp($usertotest, $passwordtotest, $entitytotest) { global $db, $conf, $dolibarr_main_cookie_cryptkey; dol_include_once('/core/login/functions_dolibarr.php'); //We first check if user & password are OK if (check_user_password_dolibarr($usertotest, $passwordtotest, $entitytotest) == '') { return ''; } // Force master entity in transversal mode $entity = $entitytotest; if (!empty($conf->multicompany->enabled) && !empty($conf->multicompany->transverse_mode)) { $entity = 1; } $sql = 'SELECT rowid, otp_seed, otp_counter'; $sql .= ' FROM ' . MAIN_DB_PREFIX . "user"; $sql .= ' WHERE login = "******"'; $sql .= ' AND entity IN (0,' . ($entity ? $entity : 1) . ")"; dol_syslog("functions_dolibarr::check_user_password_dolibarr sql=" . $sql); $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); if ($obj) { //The user has not configured an OTP key if (!$obj->otp_seed) { return $usertotest; } //Now we validate OTP $providedOTP = GETPOST('otp'); if (empty($providedOTP)) { return ''; } /** * Examples from http://es.php.net/mcrypt_encrypt */ $ciphertext_dec = base64_decode($obj->otp_seed); $key = pack('H*', $dolibarr_main_cookie_cryptkey); # recupera la IV, iv_size deberÃa crearse usando mcrypt_get_iv_size() $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv_dec = substr($ciphertext_dec, 0, $iv_size); # recupera el texto cifrado (todo excepto el $iv_size en el frente) $ciphertext_dec = substr($ciphertext_dec, $iv_size); # podrÃan eliminarse los caracteres con valor 00h del final del texto puro $otpSeed = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec); $otplib = new \Rych\OTP\HOTP($otpSeed); if ($otplib->validate($providedOTP, $obj->otp_counter)) { $obj->otp_counter++; $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET otp_counter = '" . $obj->otp_counter . "' WHERE rowid = " . $obj->rowid; $db->query($sql); // Now the user is authenticated return $usertotest; } } } return ''; }
/** * Build Select List of element associable to a businesscase * * @param string $tablename To parse * @param Lead $lead The lead * @param string $htmlname Name of the component * * @return string HTML select list of element */ function select_element($tablename, $lead, $htmlname = 'elementselect') { global $langs, $conf; switch ($tablename) { case "facture": $sql = "SELECT rowid, facnumber as ref, total as total_ht, date_valid as date_element"; break; case "contrat": $sql = "SELECT rowid, ref as ref, 0 as total_ht, date_contrat as date_element"; break; case "commande": $sql = "SELECT rowid, ref as ref, total_ht as total_ht, date_commande as date_element"; break; default: $sql = "SELECT rowid, ref, total_ht, datep as date_element"; break; } $sql .= " FROM " . MAIN_DB_PREFIX . $tablename; //TODO Fix sourcetype can be different from tablename (exemple project/projet) $sql .= " WHERE rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='" . $lead->element . "' AND sourcetype='" . $tablename . "')"; // Manage filter /*if (count($filter) > 0) { foreach ( $filter as $key => $value ) { if (($key == 's.fk_session_place') || ($key == 'f.rowid') || ($key == 's.type_session') || ($key == 's.status') || ($key == 'sale.fk_user_com')) { $sql .= ' AND ' . $key . ' = ' . $value; } else { $sql .= ' AND ' . $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; } } }*/ $sql .= " AND fk_soc=" . $lead->fk_soc; $sql .= " AND entity=" . $conf->entity; // $sql.= " AND entity IN (".getEntity($object->element,1).")"; $sql .= " ORDER BY ref DESC"; dol_syslog(get_class($this) . "::select_element sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; if ($num > 0) { $sellist = '<select class="flat" name="' . $htmlname . '">'; while ($i < $num) { $obj = $this->db->fetch_object($resql); $sellist .= '<option value="' . $obj->rowid . '">' . $obj->ref . ' (' . dol_print_date($this->db->jdate($obj->date_element), 'daytextshort') . ')'; $sellist .= (empty($obj->total_ht) ? '' : '-' . price($obj->total_ht) . $langs->getCurrencySymbol($conf->currency)) . '</option>'; $i++; } $sellist .= '</select>'; } return $sellist; } $this->db->free($resql); return null; }
/** * Load data into info_box_contents array to show array later. * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $user, $langs, $db, $conf; $this->max = $max; $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts")); if ($user->rights->banque->lire) { $sql = "SELECT rowid, ref, label, bank, number, courant, clos, rappro, url,"; $sql .= " code_banque, code_guichet, cle_rib, bic, iban_prefix,"; $sql .= " domiciliation, proprio, owner_address,"; $sql .= " account_number, currency_code,"; $sql .= " min_allowed, min_desired, comment"; $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account"; $sql .= " WHERE entity = " . $conf->entity; $sql .= " AND clos = 0"; //$sql.= " AND courant = 1"; $sql .= " ORDER BY label"; $sql .= $db->plimit($max, 0); dol_syslog(get_class($this) . "::loadBox sql=" . $sql); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; $solde_total = 0; $listofcurrencies = array(); $account_static = new Account($db); while ($i < $num) { $objp = $db->fetch_object($result); $account_static->id = $objp->rowid; $solde = $account_static->solde(0); $solde_total += $solde; $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/compta/bank/account.php?account=" . $objp->rowid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->label, 'url' => DOL_URL_ROOT . "/compta/bank/account.php?account=" . $objp->rowid); $this->info_box_contents[$i][2] = array('td' => 'align="left"', 'text' => $objp->number); $this->info_box_contents[$i][3] = array('td' => 'align="right"', 'text' => price($solde, 0, $langs, 0, 0, -1, $objp->currency_code)); $listofcurrencies[$objp->currency_code] = 1; $i++; } // Total if (count($listofcurrencies) <= 1) { $this->info_box_contents[$i][0] = array('tr' => 'class="liste_total"', 'td' => 'align="right" class="liste_total"', 'text' => $langs->trans('Total')); $this->info_box_contents[$i][1] = array('td' => 'align="right" class="liste_total"', 'text' => ' '); $this->info_box_contents[$i][2] = array('td' => 'align="right" class="liste_total"', 'text' => ' '); $totalamount = price($solde_total, 0, $langs, 0, 0, -1, $conf->currency); $this->info_box_contents[$i][3] = array('td' => 'align="right" class="liste_total"', 'text' => $totalamount); } $db->free($result); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Return if configuration is valid * * @return boolean True if configuration ok */ public function checkConfiguration() { global $langs; $errors = array(); $filename = $this->getFilename(); if (file_exists($filename) && is_writable($filename)) { dol_syslog('admin/syslog: file ' . $filename); } else { $errors[] = $langs->trans("ErrorFailedToOpenFile", $filename); } return $errors; }
/** * Load data into info_box_contents array to show array later. * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $user, $langs, $db, $conf; $this->max = $max; $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts")); if ($user->rights->banque->lire) { $sql = "SELECT rowid, ref, label, bank, number, courant, clos, rappro, url,"; $sql .= " code_banque, code_guichet, cle_rib, bic, iban_prefix as iban,"; $sql .= " domiciliation, proprio, owner_address,"; $sql .= " account_number, currency_code,"; $sql .= " min_allowed, min_desired, comment"; $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account"; $sql .= " WHERE entity = " . $conf->entity; $sql .= " AND clos = 0"; //$sql.= " AND courant = 1"; $sql .= " ORDER BY label"; $sql .= $db->plimit($max, 0); dol_syslog(get_class($this) . "::loadBox", LOG_DEBUG); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $line = 0; $solde_total = array(); $account_static = new Account($db); while ($line < $num) { $objp = $db->fetch_object($result); $account_static->id = $objp->rowid; $account_static->label = $objp->label; $account_static->number = $objp->number; $solde = $account_static->solde(0); $solde_total[$objp->currency_code] += $solde; $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $account_static->getNomUrl(1), 'asis' => 1); $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $objp->number); $this->info_box_contents[$line][] = array('td' => 'align="right"', 'text' => price($solde, 0, $langs, 0, -1, -1, $objp->currency_code)); $line++; } // Total foreach ($solde_total as $key => $solde) { $this->info_box_contents[$line][] = array('tr' => 'class="liste_total"', 'td' => 'align="left" class="liste_total"', 'text' => $langs->trans('Total') . ' ' . $key); $this->info_box_contents[$line][] = array('td' => 'align="right" class="liste_total"', 'text' => ' '); $this->info_box_contents[$line][] = array('td' => 'align="right" class="liste_total"', 'text' => price($solde, 0, $langs, 0, -1, -1, $key)); $line++; } $db->free($result); } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed")); } }
/** * Return list of social contributions. * Use mysoc->country_id or mysoc->country_code so they must be defined. * * @param string $selected Preselected type * @param string $htmlname Name of field in form * @param int $useempty Set to 1 if we want an empty value * @param int $maxlen Max length of text in combo box * @param int $help Add or not the admin help picto * @return void */ function select_type_socialcontrib($selected = '', $htmlname = 'actioncode', $useempty = 0, $maxlen = 40, $help = 1) { global $db, $langs, $user, $mysoc; if (empty($mysoc->country_id) && empty($mysoc->country_code)) { dol_print_error('', 'Call to select_type_socialcontrib with mysoc country not yet defined'); exit; } if (!empty($mysoc->country_id)) { $sql = "SELECT c.id, c.libelle as type"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales as c"; $sql .= " WHERE c.active = 1"; $sql .= " AND c.fk_pays = " . $mysoc->country_id; $sql .= " ORDER BY c.libelle ASC"; } else { $sql = "SELECT c.id, c.libelle as type"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales as c, " . MAIN_DB_PREFIX . "c_country as co"; $sql .= " WHERE c.active = 1 AND c.fk_pays = co.rowid"; $sql .= " AND co.code = '" . $mysoc->country_code . "'"; $sql .= " ORDER BY c.libelle ASC"; } dol_syslog("Form::select_type_socialcontrib", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { print '<select class="flat" name="' . $htmlname . '">'; $i = 0; if ($useempty) { print '<option value="0"> </option>'; } while ($i < $num) { $obj = $db->fetch_object($resql); print '<option value="' . $obj->id . '"'; if ($obj->id == $selected) { print ' selected="selected"'; } print '>' . dol_trunc($obj->type, $maxlen); $i++; } print '</select>'; if ($user->admin && $help) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } } else { print $langs->trans("ErrorNoSocialContributionForSellerCountry", $mysoc->country_code); } } else { dol_print_error($db, $db->lasterror()); } }
/** * Check validity of user/password/entity * If test is ko, reason must be filled into $_SESSION["dol_loginmesg"] * * @param string $usertotest Login * @param string $passwordtotest Password * @param int $entitytotest Number of instance (always 1 if module multicompany not enabled) * @return string Login if OK, '' if KO */ function check_user_password_forceuser($usertotest, $passwordtotest, $entitytotest) { // Variable dolibarr_auto_user must be defined in conf.php file global $dolibarr_auto_user; dol_syslog("functions_forceuser::check_user_password_forceuser"); $login = $dolibarr_auto_user; if (empty($login)) { $login = '******'; } if ($_SESSION["dol_loginmesg"]) { $login = ''; } return $login; }
/** * Return list of events managed by notification module * * @return array Array of events managed by notification module */ function getListOfManagedEvents() { global $conf; $ret = array(); $sql = "SELECT rowid, code, label, description, elementtype"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_action_trigger"; $sql .= $this->db->order("rang, elementtype, code"); dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) { $obj = $this->db->fetch_object($resql); $qualified = 0; // Check is this event is supported by notification module if (in_array($obj->code, $this->listofmanagedevents)) { $qualified = 1; } // Check if module for this event is active if ($qualified) { //print 'xx'.$obj->code; $element = $obj->elementtype; // Exclude events if related module is disabled if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) { $qualified = 0; } elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) { $qualified = 0; } elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) { $qualified = 0; } elseif ($element == 'shipping' && empty($conf->expedition->enabled)) { $qualified = 0; } elseif ($element == 'member' && empty($conf->adherent->enabled)) { $qualified = 0; } elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member')) && empty($conf->{$element}->enabled)) { $qualified = 0; } } if ($qualified) { $ret[] = array('rowid' => $obj->rowid, 'code' => $obj->code, 'label' => $obj->label, 'description' => $obj->description, 'elementtype' => $obj->elementtype); } $i++; } } else { dol_print_error($this->db); } return $ret; }
/** * Return if configuration is valid * * @return boolean True if configuration ok */ public function checkConfiguration() { global $langs; $errors = array(); $facility = SYSLOG_FACILITY; if ($facility) { // Only LOG_USER supported on Windows if (!empty($_SERVER["WINDIR"])) { $facility = 'LOG_USER'; } dol_syslog("admin/syslog: facility " . $facility); } else { $errors[] = $langs->trans("ErrorUnknownSyslogConstant", $facility); } return $errors; }
/** * Return combo list of differents status of a proposal * Values are id of table c_propalst * * @param string $selected Preselected value * @param int $short Use short labels * @param int $excludedraft 0=All status, 1=Exclude draft status * @param int $showempty 1=Add empty line * @return void */ function selectProposalStatus($selected = '', $short = 0, $excludedraft = 0, $showempty = 1) { global $langs; $sql = "SELECT id, code, label, active FROM " . MAIN_DB_PREFIX . "c_propalst"; $sql .= " WHERE active = 1"; dol_syslog(get_class($this) . "::selectProposalStatus", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { print '<select class="flat" name="propal_statut">'; if ($showempty) { print '<option value=""> </option>'; } $num = $this->db->num_rows($resql); $i = 0; if ($num) { while ($i < $num) { $obj = $this->db->fetch_object($resql); if ($excludedraft) { if ($obj->code == 'Draft' || $obj->code == 'PR_DRAFT') { $i++; continue; } } if ($selected == $obj->id) { print '<option value="' . $obj->id . '" selected>'; } else { print '<option value="' . $obj->id . '">'; } $key = $obj->code; if ($langs->trans("PropalStatus" . $key . ($short ? 'Short' : '')) != "PropalStatus" . $key . ($short ? 'Short' : '')) { print $langs->trans("PropalStatus" . $key . ($short ? 'Short' : '')); } else { $conv_to_new_code = array('PR_DRAFT' => 'Draft', 'PR_OPEN' => 'Opened', 'PR_CLOSED' => 'Closed', 'PR_SIGNED' => 'Signed', 'PR_NOTSIGNED' => 'NotSigned', 'PR_FAC' => 'Billed'); if (!empty($conv_to_new_code[$obj->code])) { $key = $conv_to_new_code[$obj->code]; } print $langs->trans("PropalStatus" . $key . ($short ? 'Short' : '')) != "PropalStatus" . $key . ($short ? 'Short' : '') ? $langs->trans("PropalStatus" . $key . ($short ? 'Short' : '')) : $obj->label; } print '</option>'; $i++; } } print '</select>'; } else { dol_print_error($this->db); } }
/** * Instantiation of DAO class * * @return int 0 * @deprecated Using getInstanceDao should not be used. */ private function getInstanceDao() { dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING); if (!is_object($this->object)) { $modelclassfile = dol_buildpath('/' . $this->dirmodule . '/canvas/' . $this->canvas . '/dao_' . $this->targetmodule . '_' . $this->canvas . '.class.php'); if (file_exists($modelclassfile)) { // Include dataservice class (model) $ret = (require_once $modelclassfile); if ($ret) { // Instantiate dataservice class (model) $modelclassname = 'Dao' . ucfirst($this->targetmodule) . ucfirst($this->canvas); $this->object = new $modelclassname($this->db); } } } return 0; }
/** * Function called when a Dolibarrr business event is done. * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) * * @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 */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { // Mettre ici le code a executer en reaction de l'action // Les donnees de l'action sont stockees dans $object if ($action == 'PAYPAL_PAYMENT_OK') { dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". source=" . $object->source . " ref=" . $object->ref); if (!empty($object->source)) { if ($object->source == 'membersubscription') { //require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherents.class.php'; // TODO add subscription treatment } else { require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; $soc = new Societe($this->db); // Parse element/subelement (ex: project_task) $element = $path = $filename = $object->source; if (preg_match('/^([^_]+)_([^_]+)/i', $object->source, $regs)) { $element = $path = $regs[1]; $filename = $regs[2]; } // For compatibility if ($element == 'order') { $path = $filename = 'commande'; } if ($element == 'invoice') { $path = 'compta/facture'; $filename = 'facture'; } dol_include_once('/' . $path . '/class/' . $filename . '.class.php'); $classname = ucfirst($filename); $obj = new $classname($this->db); $ret = $obj->fetch('', $object->ref); if ($ret < 0) { return -1; } // Add payer id $soc->setValueFrom('ref_int', $object->payerID, 'societe', $obj->socid); // Add transaction id $obj->setValueFrom('ref_int', $object->resArray["TRANSACTIONID"]); } } else { // TODO add free tag treatment } } return 0; }
/** * Get produt or service * * @param array $authentication Array of authentication information * @param int $id Id of object * @param string $ref Ref of object * @param ref_ext $ref_ext Ref external of object * @return mixed */ function getSkeleton($authentication, $id, $ref = '', $ref_ext = '') { global $db, $conf, $langs; dol_syslog("Function: getSkeleton login="******" id=" . $id . " ref=" . $ref . " ref_ext=" . $ref_ext); if ($authentication['entity']) { $conf->entity = $authentication['entity']; } // Init and check authentication $objectresp = array(); $errorcode = ''; $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); // Check parameters if (!$error && ($id && $ref || $id && $ref_ext || $ref && $ref_ext)) { $error++; $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; } if (!$error) { $fuser->getrights(); if ($fuser->rights->skeleton->read) { $skeleton = new Skeleton($db); $result = $skeleton->fetch($id, $ref, $ref_ext); if ($result > 0) { // Create $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'skeleton' => array('prop1' => $skeleton->prop1, 'prop2' => $skeleton->prop2)); } else { $error++; $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id=' . $id . ' nor ref=' . $ref . ' nor ref_ext=' . $ref_ext; } } else { $error++; $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }
/** * Return amount of payments already done * * @return int Amount of payment already done, <0 if KO */ function getSommePaiement() { $table = 'paiement_facture'; $field = 'fk_facture'; if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { $table = 'paiementfourn_facturefourn'; $field = 'fk_facturefourn'; } $sql = 'SELECT sum(amount) as amount'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $table; $sql .= ' WHERE ' . $field . ' = ' . $this->id; dol_syslog(get_class($this) . "::getSommePaiement sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); $this->db->free($resql); return $obj->amount; } else { $this->error = $this->db->lasterror(); return -1; } }
/** * Constructor * * @param string $type 'country' or 'city' * @param string $datfile Data file */ function __construct($type, $datfile) { if ($type == 'country') { // geoip may have been already included with PEAR if (!function_exists('geoip_country_code_by_name')) { $res = (include_once GEOIP_PATH . 'geoip.inc'); } } else { if ($type == 'city') { // geoip may have been already included with PEAR if (!function_exists('geoip_country_code_by_name')) { $res = (include_once GEOIP_PATH . 'geoipcity.inc'); } } else { print 'ErrorBadParameterInConstructor'; return 0; } } // Here, function exists (embedded into PHP or exists because we made include) if (empty($type) || empty($datfile)) { $this->errorlabel = 'Constructor was called with no datafile parameter'; dol_syslog('DolGeoIP ' . $this->errorlabel, LOG_ERR); return 0; } if (!file_exists($datfile) || !is_readable($datfile)) { $this->error = 'ErrorGeoIPClassNotInitialized'; $this->errorlabel = "Datafile " . $datfile . " not found"; dol_syslog('DolGeoIP ' . $this->errorlabel, LOG_ERR); return 0; } if (function_exists('geoip_open')) { $this->gi = geoip_open($datfile, GEOIP_STANDARD); } else { $this->gi = 'NOGI'; // We are using embedded php geoip functions //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name'); //print geoip_database_info(); } }