Пример #1
0
 /**
  * 	Load setup values into conf object (read llx_const)
  *
  * 	@param      DoliDB		$db		Handler d'acces base
  * 	@return     int					< 0 if KO, >= 0 if OK
  */
 function setValues()
 {
     global $conf;
     dol_syslog(get_class($this) . "::setValues", LOG_INFO, get_class($this));
     // Avoid warning if not defined
     if (empty($this->db->dolibarr_main_db_encryption)) {
         $this->db->dolibarr_main_db_encryption = 0;
     }
     if (empty($this->db->dolibarr_main_db_cryptkey)) {
         $this->db->dolibarr_main_db_cryptkey = '';
     }
     /*
      * Definition de toutes les constantes globales d'environnement
      * - En constante php (TODO a virer)
      * - En $this->global->key=value
      */
     $found = false;
     $result = dol_getcache("const");
     if (is_object($result)) {
         $found = true;
     }
     if (!$found) {
         $result = array();
         try {
             $result = $this->load('const');
             //print_r($result);
             dol_setcache("const", $result);
         } catch (Exception $e) {
             dol_print_error("", $e->getMessage());
             exit;
         }
     }
     $i = 0;
     if (count($result->values) == 0) {
         dol_print_error("", "Error in const document : values is empty !");
         exit;
     }
     foreach ($result->values as $key => $value) {
         if ($key) {
             if (!defined("{$key}")) {
                 define("{$key}", $value);
             }
             // In some cases, the constant might be already forced (Example: SYSLOG_FILE_ON and SYSLOG_FILE during install)
             $this->global->{$key} = $value;
             if ($value && preg_match('/^MAIN_MODULE_/', $key)) {
                 // If this is constant for a new tab page activated by a module.
                 if (preg_match('/^MAIN_MODULE_([A-Z_]+)_TABS_/i', $key)) {
                     $params = explode(':', $value, 2);
                     $this->tabs_modules[$params[0]][] = $value;
                 } elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_SMS$/i', $key, $reg)) {
                     $modulename = strtolower($reg[1]);
                     $this->sms_engine_modules[$modulename] = $modulename;
                     // Add this module in list of modules that provide SMS
                 } elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_([A-Z]+)$/i', $key, $reg)) {
                     $modulename = strtolower($reg[1]);
                     $partname = strtolower($reg[2]);
                     //$varname = $partname.'_modules';  // TODO deprecated
                     //if (! isset($this->$varname) || ! is_array($this->$varname)) { $this->$varname = array(); } // TODO deprecated
                     if (!isset($this->modules_parts[$partname]) || !is_array($this->modules_parts[$partname])) {
                         $this->modules_parts[$partname] = array();
                     }
                     $arrValue = json_decode($value, true);
                     if (is_array($arrValue) && !empty($arrValue)) {
                         $value = $arrValue;
                     } else {
                         if (in_array($partname, array('login', 'menus', 'substitutions', 'triggers', 'tpl', 'theme'))) {
                             $value = '/' . $modulename . '/core/' . $partname . '/';
                         } else {
                             if (in_array($partname, array('models'))) {
                                 $value = '/' . $modulename . '/';
                             } else {
                                 if ($value == 1) {
                                     $value = '/' . $modulename . '/core/modules/' . $partname . '/';
                                 }
                             }
                         }
                     }
                     //$this->$varname = array_merge($this->$varname, array($modulename => $value));  // TODO deprecated
                     $this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $value));
                 }
             }
         }
         $i++;
     }
     // load configuration module
     $object = new DolibarrModules($this->db);
     $result = $object->getView("list", array(), true);
     foreach ($result->rows as $aRow) {
         $modulename = $aRow->key;
         $this->{$modulename} = $aRow->value;
         $this->modules[] = $modulename;
     }
     //print_r($this);exit;
     //var_dump($this->modules);
     //var_dump($this->modules_parts);
     // Second or others levels object
     $this->propal->cloture = (object) array();
     $this->propal->facturation = (object) array();
     $this->commande->client = (object) array();
     $this->commande->fournisseur = (object) array();
     $this->facture->client = (object) array();
     $this->facture->fournisseur = (object) array();
     $this->fournisseur->commande = (object) array();
     $this->fournisseur->facture = (object) array();
     $this->contrat->services = (object) array();
     $this->contrat->services->inactifs = (object) array();
     $this->contrat->services->expires = (object) array();
     $this->adherent->cotisation = (object) array();
     $this->bank->rappro = (object) array();
     $this->bank->cheque = (object) array();
     // Clean some variables
     if (empty($this->global->MAIN_MENU_STANDARD)) {
         $this->global->MAIN_MENU_STANDARD = "eldy_backoffice.php";
     }
     if (empty($this->global->MAIN_MENUFRONT_STANDARD)) {
         $this->global->MAIN_MENUFRONT_STANDARD = "eldy_frontoffice.php";
     }
     if (empty($this->global->MAIN_MENU_SMARTPHONE)) {
         $this->global->MAIN_MENU_SMARTPHONE = "eldy_backoffice.php";
     }
     // Use eldy by default because smartphone does not work on all phones
     if (empty($this->global->MAIN_MENUFRONT_SMARTPHONE)) {
         $this->global->MAIN_MENUFRONT_SMARTPHONE = "eldy_frontoffice.php";
     }
     // Ue eldy by default because smartphone does not work on all phones
     // Variable globales LDAP
     if (empty($this->global->LDAP_FIELD_FULLNAME)) {
         $this->global->LDAP_FIELD_FULLNAME = '';
     }
     if (!isset($this->global->LDAP_KEY_USERS)) {
         $this->global->LDAP_KEY_USERS = $this->global->LDAP_FIELD_FULLNAME;
     }
     if (!isset($this->global->LDAP_KEY_GROUPS)) {
         $this->global->LDAP_KEY_GROUPS = $this->global->LDAP_FIELD_FULLNAME;
     }
     if (!isset($this->global->LDAP_KEY_CONTACTS)) {
         $this->global->LDAP_KEY_CONTACTS = $this->global->LDAP_FIELD_FULLNAME;
     }
     if (!isset($this->global->LDAP_KEY_MEMBERS)) {
         $this->global->LDAP_KEY_MEMBERS = $this->global->LDAP_FIELD_FULLNAME;
     }
     // Load translation object with current language
     if (empty($this->global->MAIN_LANG_DEFAULT)) {
         $this->global->MAIN_LANG_DEFAULT = "en_US";
     }
     // By default, we repeat info on all tabs
     if (!isset($this->global->MAIN_REPEATCONTACTONEACHTAB)) {
         $this->global->MAIN_REPEATCONTACTONEACHTAB = 1;
     }
     if (!isset($this->global->MAIN_REPEATADDRESSONEACHTAB)) {
         $this->global->MAIN_REPEATADDRESSONEACHTAB = 1;
     }
     $rootfordata = DOL_DATA_ROOT;
     $rootforuser = DOL_DATA_ROOT;
     // Define default dir_output and dir_temp for directories of modules
     foreach ($this->modules as $module) {
         $this->{$module}->multidir_output = array($this->entity => $rootfordata . "/" . $module);
         $this->{$module}->multidir_temp = array($this->entity => $rootfordata . "/" . $module . "/temp");
         // For backward compatibility
         $this->{$module}->dir_output = $rootfordata . "/" . $module;
         $this->{$module}->dir_temp = $rootfordata . "/" . $module . "/temp";
     }
     // For mycompany storage
     $this->mycompany->dir_output = $rootfordata . "/mycompany";
     $this->mycompany->dir_temp = $rootfordata . "/mycompany/temp";
     // For admin storage
     $this->admin->dir_output = $rootfordata . '/admin';
     $this->admin->dir_temp = $rootfordata . '/admin/temp';
     // For user storage
     $this->user->multidir_output = array($this->entity => $rootfordata . "/users");
     $this->user->multidir_temp = array($this->entity => $rootfordata . "/users/temp");
     // For backward compatibility
     $this->user->dir_output = $rootforuser . "/users";
     $this->user->dir_temp = $rootforuser . "/users/temp";
     // For propal storage
     $this->propal->dir_output = $rootforuser . "/propale";
     $this->propal->dir_temp = $rootforuser . "/propale/temp";
     // Exception: Some dir are not the name of module. So we keep exception here
     // for backward compatibility.
     // Sous module bons d'expedition
     $this->expedition_bon->enabled = defined("MAIN_SUBMODULE_EXPEDITION") ? MAIN_SUBMODULE_EXPEDITION : 0;
     // Sous module bons de livraison
     $this->livraison_bon->enabled = defined("MAIN_SUBMODULE_LIVRAISON") ? MAIN_SUBMODULE_LIVRAISON : 0;
     // Module fournisseur
     $this->fournisseur->commande->dir_output = $rootfordata . "/fournisseur/commande";
     $this->fournisseur->commande->dir_temp = $rootfordata . "/fournisseur/commande/temp";
     $this->fournisseur->facture->dir_output = $rootfordata . "/fournisseur/facture";
     $this->fournisseur->facture->dir_temp = $rootfordata . "/fournisseur/facture/temp";
     // Module product/service
     $this->product->multidir_output = array($this->entity => $rootfordata . "/produit");
     $this->product->multidir_temp = array($this->entity => $rootfordata . "/produit/temp");
     $this->service->multidir_output = array($this->entity => $rootfordata . "/produit");
     $this->service->multidir_temp = array($this->entity => $rootfordata . "/produit/temp");
     // For backward compatibility
     $this->product->dir_output = $rootfordata . "/produit";
     $this->product->dir_temp = $rootfordata . "/produit/temp";
     $this->service->dir_output = $rootfordata . "/produit";
     $this->service->dir_temp = $rootfordata . "/produit/temp";
     // Module contrat
     $this->contrat->dir_output = $rootfordata . "/contracts";
     $this->contrat->dir_temp = $rootfordata . "/contracts/temp";
     // Set some default values
     // societe
     if (empty($this->global->SOCIETE_CODECLIENT_ADDON)) {
         $this->global->SOCIETE_CODECLIENT_ADDON = "mod_codeclient_leopard";
     }
     if (empty($this->global->SOCIETE_CODEFOURNISSEUR_ADDON)) {
         $this->global->SOCIETE_CODEFOURNISSEUR_ADDON = $this->global->SOCIETE_CODECLIENT_ADDON;
     }
     if (empty($this->global->SOCIETE_CODECOMPTA_ADDON)) {
         $this->global->SOCIETE_CODECOMPTA_ADDON = "mod_codecompta_panicum";
     }
     // Security
     if (empty($this->global->USER_PASSWORD_GENERATED)) {
         $this->global->USER_PASSWORD_GENERATED = 'standard';
     }
     // Default password generator
     if (empty($this->global->MAIN_UMASK)) {
         $this->global->MAIN_UMASK = '0664';
     }
     // Default mask
     // conf->use_javascript_ajax
     $this->use_javascript_ajax = 1;
     if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) {
         $this->use_javascript_ajax = !$this->global->MAIN_DISABLE_JAVASCRIPT;
     }
     // If no javascript_ajax, Ajax features are disabled.
     if (!$this->use_javascript_ajax) {
         $this->global->PRODUIT_USE_SEARCH_TO_SELECT = 0;
     }
     // conf->currency
     if (empty($this->global->MAIN_MONNAIE)) {
         $this->global->MAIN_MONNAIE = 'EUR';
     }
     $this->currency = $this->global->MAIN_MONNAIE;
     // conf->global->COMPTA_MODE = Option des modules Comptabilites (simple ou expert). Defini le mode de calcul des etats comptables (CA,...)
     if (empty($this->global->COMPTA_MODE)) {
         $this->global->COMPTA_MODE = 'RECETTES-DEPENSES';
     }
     // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES'
     // conf->liste_limit = constante de taille maximale des listes
     if (empty($this->global->MAIN_SIZE_LISTE_LIMIT)) {
         $this->global->MAIN_SIZE_LISTE_LIMIT = 25;
     }
     $this->liste_limit = $this->global->MAIN_SIZE_LISTE_LIMIT;
     // conf->liste_limit = constante de taille maximale des listes
     if (empty($this->global->MAIN_SIZE_VIEW_LIMIT)) {
         $this->global->MAIN_SIZE_VIEW_LIMIT = 10000;
     }
     $this->view_limit = $this->global->MAIN_SIZE_VIEW_LIMIT;
     // conf->product->limit_size = constante de taille maximale des select de produit
     if (!isset($this->global->PRODUIT_LIMIT_SIZE)) {
         $this->global->PRODUIT_LIMIT_SIZE = 100;
     }
     $this->product->limit_size = $this->global->PRODUIT_LIMIT_SIZE;
     // conf->theme et $this->css
     if (empty($this->global->MAIN_THEME)) {
         $this->global->MAIN_THEME = "eldy";
     }
     $this->theme = $this->global->MAIN_THEME;
     $this->css = "/theme/" . $this->theme . "/style.css.php";
     // conf->email_from = email pour envoi par dolibarr des mails automatiques
     $this->email_from = "*****@*****.**";
     if (!empty($this->global->MAIN_MAIL_EMAIL_FROM)) {
         $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM;
     }
     // conf->notification->email_from = email pour envoi par Dolibarr des notifications
     $this->notification->email_from = $this->email_from;
     if (!empty($this->global->NOTIFICATION_EMAIL_FROM)) {
         $this->notification->email_from = $this->global->NOTIFICATION_EMAIL_FROM;
     }
     // conf->mailing->email_from = email pour envoi par Dolibarr des mailings
     $this->mailing->email_from = $this->email_from;
     if (!empty($this->global->MAILING_EMAIL_FROM)) {
         $this->mailing->email_from = $this->global->MAILING_EMAIL_FROM;
     }
     // Format for date (used by default when not found or searched in lang)
     $this->format_date_short = "%d/%m/%Y";
     // Format of day with PHP/C tags (strftime functions)
     $this->format_date_short_java = "dd/MM/yyyy";
     // Format of day with Java tags
     $this->format_hour_short = "%H:%M";
     $this->format_hour_short_duration = "%H:%M";
     $this->format_date_text_short = "%d %b %Y";
     $this->format_date_text = "%d %B %Y";
     $this->format_date_hour_short = "%d/%m/%Y %H:%M";
     $this->format_date_hour_text_short = "%d %b %Y %H:%M";
     $this->format_date_hour_text = "%d %B %Y %H:%M";
     // Limites decimales si non definie (peuvent etre egale a 0)
     if (!isset($this->global->MAIN_MAX_DECIMALS_UNIT)) {
         $this->global->MAIN_MAX_DECIMALS_UNIT = 5;
     }
     if (!isset($this->global->MAIN_MAX_DECIMALS_TOT)) {
         $this->global->MAIN_MAX_DECIMALS_TOT = 2;
     }
     if (!isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) {
         $this->global->MAIN_MAX_DECIMALS_SHOWN = 8;
     }
     // Timeouts
     if (empty($this->global->MAIN_USE_CONNECT_TIMEOUT)) {
         $this->global->MAIN_USE_CONNECT_TIMEOUT = 10;
     }
     if (empty($this->global->MAIN_USE_RESPONSE_TIMEOUT)) {
         $this->global->MAIN_USE_RESPONSE_TIMEOUT = 30;
     }
     // Set default variable to calculate VAT as if option tax_mode was 0 (standard)
     if (empty($this->global->TAX_MODE_SELL_PRODUCT)) {
         $this->global->TAX_MODE_SELL_PRODUCT = 'invoice';
     }
     if (empty($this->global->TAX_MODE_BUY_PRODUCT)) {
         $this->global->TAX_MODE_BUY_PRODUCT = 'invoice';
     }
     if (empty($this->global->TAX_MODE_SELL_SERVICE)) {
         $this->global->TAX_MODE_SELL_SERVICE = 'payment';
     }
     if (empty($this->global->TAX_MODE_BUY_SERVICE)) {
         $this->global->TAX_MODE_BUY_SERVICE = 'payment';
     }
     // Delay before warnings
     $this->actions->warning_delay = (isset($this->global->MAIN_DELAY_ACTIONS_TODO) ? $this->global->MAIN_DELAY_ACTIONS_TODO : 7) * 24 * 60 * 60;
     $this->commande->client->warning_delay = (isset($this->global->MAIN_DELAY_ORDERS_TO_PROCESS) ? $this->global->MAIN_DELAY_ORDERS_TO_PROCESS : 2) * 24 * 60 * 60;
     $this->commande->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS) ? $this->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS : 7) * 24 * 60 * 60;
     $this->propal->cloture->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_CLOSE) ? $this->global->MAIN_DELAY_PROPALS_TO_CLOSE : 0) * 24 * 60 * 60;
     $this->propal->facturation->warning_delay = (isset($this->global->MAIN_DELAY_PROPALS_TO_BILL) ? $this->global->MAIN_DELAY_PROPALS_TO_BILL : 0) * 24 * 60 * 60;
     $this->facture->client->warning_delay = (isset($this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED) ? $this->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED : 0) * 24 * 60 * 60;
     $this->facture->fournisseur->warning_delay = (isset($this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY) ? $this->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY : 0) * 24 * 60 * 60;
     $this->contrat->services->inactifs->warning_delay = (isset($this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES) ? $this->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES : 0) * 24 * 60 * 60;
     $this->contrat->services->expires->warning_delay = (isset($this->global->MAIN_DELAY_RUNNING_SERVICES) ? $this->global->MAIN_DELAY_RUNNING_SERVICES : 0) * 24 * 60 * 60;
     $this->adherent->cotisation->warning_delay = (isset($this->global->MAIN_DELAY_MEMBERS) ? $this->global->MAIN_DELAY_MEMBERS : 0) * 24 * 60 * 60;
     $this->bank->rappro->warning_delay = (isset($this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE) ? $this->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE : 0) * 24 * 60 * 60;
     $this->bank->cheque->warning_delay = (isset($this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT) ? $this->global->MAIN_DELAY_CHEQUES_TO_DEPOSIT : 0) * 24 * 60 * 60;
     // For backward compatibility
     if (isset($this->product)) {
         $this->produit = $this->product;
     }
     if (isset($this->facture)) {
         $this->invoice = $this->facture;
     }
     if (isset($this->commande)) {
         $this->order = $this->commande;
     }
     if (isset($this->contrat)) {
         $this->contract = $this->contrat;
     }
     if (isset($this->categorie)) {
         $this->category = $this->categorie;
     }
     // Define menu manager in setup
     if (empty($user->societe_id)) {
         // If internal user or not defined
         $this->top_menu = empty($this->global->MAIN_MENU_STANDARD_FORCED) ? $this->global->MAIN_MENU_STANDARD : $this->global->MAIN_MENU_STANDARD_FORCED;
         $this->smart_menu = empty($this->global->MAIN_MENU_SMARTPHONE_FORCED) ? $this->global->MAIN_MENU_SMARTPHONE : $this->global->MAIN_MENU_SMARTPHONE_FORCED;
     } else {
         // If external user
         $this->top_menu = empty($this->global->MAIN_MENUFRONT_STANDARD_FORCED) ? $this->global->MAIN_MENUFRONT_STANDARD : $this->global->MAIN_MENUFRONT_STANDARD_FORCED;
         $this->smart_menu = empty($this->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) ? $this->global->MAIN_MENUFRONT_SMARTPHONE : $this->global->MAIN_MENUFRONT_SMARTPHONE_FORCED;
     }
 }
Пример #2
0
 /** Call a view on couchdb
  * 
  * @param	$name			string			name of the view
  * @param	$params			array			params ['group'],['level'],['key'],...
  * @param	$cache			bool			load from cache
  * @return  array
  */
 public function getView($name, $params = array(), $cache = false)
 {
     global $conf;
     $found = false;
     if ($cache) {
         $result = dol_getcache(get_class($this) . ":" . $name);
         if (is_object($result)) {
             $found = true;
         }
     }
     if (!$found) {
         $result = new stdClass();
         try {
             /* if (!empty($conf->view_limit))
                $params['limit'] = $conf->global->MAIN_SIZE_LISTE_LIMIT; */
             //$params['limit'] = $conf->view_limit;
             if (is_array($params)) {
                 $this->couchdb->setQueryParameters($params);
             }
             $result = $this->couchdb->getView(get_class($this), $name);
             if ($cache) {
                 dol_setcache(get_class($this) . ":" . $name, $result);
             }
         } catch (Exception $e) {
             error_log($e->getMessage());
             dol_syslog(get_class($this) . "::getView " . $error, LOG_WARN);
             $result->total_rows = 0;
         }
     }
     return $result;
 }
Пример #3
0
 /**
  * Core function to output top menu auguria
  *
  * @param 	DoliDB	$db				Database handler
  * @param 	string	$atarget		Target
  * @param 	int		$type_user     	0=Internal,1=External,2=All
  * @return	void
  */
 function print_auguria_menu($type_user)
 {
     global $user, $langs;
     // On sauve en session le menu principal choisi
     if (isset($_GET["idmenu"])) {
         dol_setcache("idmenu", $_GET["idmenu"]);
         $this->idmenu = $_GET["idmenu"];
     }
     $tabMenu = array();
     $this->print_start_menu_array_auguria();
     //print_r($result);exit;
     $i = 0;
     $selectnav = array();
     foreach ($this->topmenu as $aRow) {
         $newTabMenu = $aRow->value;
         $newTabMenu = $this->verifyMenu($newTabMenu);
         if ($newTabMenu->enabled == true) {
             $idsel = empty($newTabMenu->_id) ? 'none' : $newTabMenu->_id;
             if ($newTabMenu->perms == true) {
                 // Is allowed
                 $url = $this->menuURL($newTabMenu, $newTabMenu->_id);
                 //print $url;exit;
                 // Define the class (top menu selected or not)
                 $classname = 'mb_parent';
                 if ($i == 0) {
                     $classname .= ' first_el';
                 }
                 if (empty($this->idmenu)) {
                     $this->idmenu = dol_getcache('idmenu');
                 }
                 // For cache optimisation
                 if (!empty($this->idmenu) && $this->menuSelected($newTabMenu)) {
                     $classname .= ' pageselected';
                     $this->selected[0]->name = $newTabMenu->title;
                     $this->selected[0]->url = $url;
                 }
                 print '<li>';
                 print '<a class="' . $classname . '" href="' . $url . '">';
                 print $newTabMenu->title;
                 print '</a>';
                 // Submenu level 1
                 $selected = $this->print_submenu($newTabMenu->_id, 1);
                 if ($selected) {
                     $this->selected[0]->name = $newTabMenu->title;
                     $this->selected[0]->url = $url;
                 }
                 print '</li>';
                 $i++;
             }
         }
     }
     $this->print_end_menu_array_auguria();
     print "\n";
 }
Пример #4
0
 /**
  *  Load translation key-value for a particular file, into a memory array.
  *  If data for file already loaded, do nothing.
  * 	All data in translation array are stored in UTF-8 format.
  *  tab_loaded is completed with $domain key.
  *  Warning: MAIN_USE_CUSTOM_TRANSLATION is an old deprecated feature. Do not use it. It will revert
  *  rule "we keep first entry found with we keep last entry found" so it is probably not what you want to do.
  *
  *  Value for hash are: 1:Loaded from disk, 2:Not found, 3:Loaded from cache
  *
  *  @param	string	$domain      		File name to load (.lang file). Must be "file" or "file@module" for module language files:
  *										If $domain is "file@module" instead of "file" then we look for module lang file
  *										in htdocs/custom/modules/mymodule/langs/code_CODE/file.lang
  *										then in htdocs/module/langs/code_CODE/file.lang instead of htdocs/langs/code_CODE/file.lang
  *  @param	integer	$alt         		0 (try xx_ZZ then 1), 1 (try xx_XX then 2), 2 (try en_US)
  * 	@param	int		$stopafterdirection	Stop when the DIRECTION tag is found (optimize speed)
  * 	@param	int		$forcelangdir		To force a different lang directory
  *	@return	int							<0 if KO, 0 if already loaded or loading not required, >0 if OK
  */
 function Load($domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = '')
 {
     global $conf;
     // Check parameters
     if (empty($domain)) {
         dol_print_error('', get_class($this) . "::Load ErrorWrongParameters");
         exit;
     }
     if ($this->defaultlang == 'none_NONE') {
         return 0;
     }
     // Special language code to not translate keys
     //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang);
     $newdomain = $domain;
     $modulename = '';
     // Search if a module directory name is provided into lang file name
     if (preg_match('/^([^@]+)@([^@]+)$/i', $domain, $regs)) {
         $newdomain = $regs[1];
         $modulename = $regs[2];
     }
     // Check cache
     if (!empty($this->_tab_loaded[$newdomain])) {
         //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain);
         return 0;
     }
     $fileread = 0;
     $langofdir = empty($forcelangdir) ? $this->defaultlang : $forcelangdir;
     // Redefine alt
     $langarray = explode('_', $langofdir);
     if ($alt < 1 && isset($langarray[1]) && strtolower($langarray[0]) == strtolower($langarray[1])) {
         $alt = 1;
     }
     if ($alt < 2 && strtolower($langofdir) == 'en_us') {
         $alt = 2;
     }
     if (empty($langofdir)) {
         dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
         return -1;
     }
     foreach ($this->dir as $keydir => $searchdir) {
         // Directory of translation files
         $file_lang = $searchdir . ($modulename ? '/' . $modulename : '') . "/langs/" . $langofdir . "/" . $newdomain . ".lang";
         $file_lang_osencoded = dol_osencode($file_lang);
         $filelangexists = is_file($file_lang_osencoded);
         //dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists);
         if ($filelangexists) {
             // TODO Move cache read out of loop on dirs or at least filelangexists
             $found = false;
             // Enable caching of lang file in memory (not by default)
             $usecachekey = '';
             // Using a memcached server
             if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) {
                 $usecachekey = $newdomain . '_' . $langofdir . '_' . md5($file_lang);
                 // Should not contains special chars
             } else {
                 if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && $conf->global->MAIN_OPTIMIZE_SPEED & 0x2) {
                     $usecachekey = $newdomain;
                 }
             }
             if ($usecachekey) {
                 //dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey);
                 //global $aaa; $aaa+=1;
                 //print $aaa." ".$usecachekey."\n";
                 require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
                 $tmparray = dol_getcache($usecachekey);
                 if (is_array($tmparray) && count($tmparray)) {
                     $this->tab_translate = array_merge($tmparray, $this->tab_translate);
                     // Already found values tab_translate overwrites duplicates
                     //print $newdomain."\n";
                     //var_dump($this->tab_translate);
                     if ($alt == 2) {
                         $fileread = 1;
                     }
                     $found = true;
                     // Found in dolibarr PHP cache
                 }
             }
             if (!$found) {
                 if ($fp = @fopen($file_lang, "rt")) {
                     if ($usecachekey) {
                         $tabtranslatedomain = array();
                     }
                     // To save lang content in cache
                     while ($line = fgets($fp, 4096)) {
                         if ($line[0] != "\n" && $line[0] != " " && $line[0] != "#") {
                             $tab = explode('=', $line, 2);
                             $key = trim($tab[0]);
                             //print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
                             if ((!empty($conf->global->MAIN_USE_CUSTOM_TRANSLATION) || empty($this->tab_translate[$key])) && isset($tab[1])) {
                                 $value = trim(preg_replace('/\\n/', "\n", $tab[1]));
                                 if ($key == 'DIRECTION') {
                                     if ($alt < 2 || empty($this->tab_translate[$key])) {
                                         $this->tab_translate[$key] = $value;
                                         if ($stopafterdirection) {
                                             break;
                                         } else {
                                             if ($usecachekey) {
                                                 $tabtranslatedomain[$key] = $value;
                                             }
                                         }
                                     }
                                 } else {
                                     $this->tab_translate[$key] = $value;
                                     if ($usecachekey) {
                                         $tabtranslatedomain[$key] = $value;
                                     }
                                     // To save lang content in cache
                                 }
                             }
                         }
                     }
                     fclose($fp);
                     $fileread = 1;
                     // TODO Move cache write out of loop on dirs
                     // To save lang content for usecachekey into cache
                     if ($usecachekey && count($tabtranslatedomain)) {
                         $ressetcache = dol_setcache($usecachekey, $tabtranslatedomain);
                         if ($ressetcache < 0) {
                             $error = 'Failed to set cache for usecachekey=' . $usecachekey . ' result=' . $ressetcache;
                             dol_syslog($error, LOG_ERR);
                         }
                     }
                     if (empty($conf->global->MAIN_FORCELANGDIR) && empty($conf->global->MAIN_USE_CUSTOM_TRANSLATION)) {
                         break;
                     }
                     // Break loop on each root dir. If a module has forced dir, we do not stop loop.
                 }
             }
         }
     }
     // Now we complete with next file
     if ($alt == 0) {
         // This function MUST NOT contains call to syslog
         //dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG);
         $langofdir = strtolower($langarray[0]) . '_' . strtoupper($langarray[0]);
         $this->load($domain, $alt + 1, $stopafterdirection, $langofdir);
     }
     // Now we complete with reference en_US/fr_FR/es_ES file
     if ($alt == 1) {
         // This function MUST NOT contains call to syslog
         //dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG);
         $langofdir = 'en_US';
         //if (preg_match('/^fr/i',$langarray[0])) $langofdir='fr_FR';
         //if (preg_match('/^es/i',$langarray[0])) $langofdir='es_ES';
         $this->load($domain, $alt + 1, $stopafterdirection, $langofdir);
     }
     if ($alt == 2) {
         if ($fileread) {
             $this->_tab_loaded[$newdomain] = 1;
         }
         // Set domain file as loaded
         if (empty($this->_tab_loaded[$newdomain])) {
             $this->_tab_loaded[$newdomain] = 2;
         }
         // Marque ce fichier comme non trouve
     }
     // Check to be sure that SeparatorDecimal differs from SeparatorThousand
     if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) {
         $this->tab_translate["SeparatorThousand"] = '';
     }
     return 1;
 }
Пример #5
0
     // Old version
 }
 $object = new $class($db);
 $output = array("sEcho" => intval($_GET['sEcho']), "iTotalRecords" => 0, "iTotalDisplayRecords" => 0, "aaData" => array());
 if ($bServerSide && $_GET['sSearch']) {
     $result = $object->getIndexedView($json, array('limit' => intval(empty($_GET['iDisplayLength']) ? $conf->view_limit : $_GET['iDisplayLength']), 'q' => $_GET['sSearch'] . "*", 'skip' => intval($_GET['iDisplayStart'])));
 } else {
     $result = $object->getView($json, array('limit' => intval(empty($_GET['iDisplayLength']) ? $conf->view_limit : $_GET['iDisplayLength']), 'skip' => intval($_GET['iDisplayStart'])));
     dol_setcache("total_rows", $result->total_rows);
 }
 if (empty($result->total_rows)) {
     $bServerSide = 0;
 }
 //print_r($result);
 //exit;
 $output["iTotalRecords"] = dol_getcache("total_rows");
 $output["iTotalDisplayRecords"] = $result->total_rows;
 if (isset($result->rows)) {
     foreach ($result->rows as $aRow) {
         unset($aRow->value->class);
         unset($aRow->value->_rev);
         $output["aaData"][] = clone $aRow->value;
         unset($aRow);
     }
 }
 //error_log(json_encode($result));
 //sorting
 if ($bServerSide) {
     $object->sortDatatable($output["aaData"], $_GET['mDataProp_' . $_GET['iSortCol_0']], $_GET['sSortDir_0']);
 }
 header('Content-type: application/json');
Пример #6
0
 /**
  *  Load translation key-value for a particular file, into a memory array.
  *  If data for file already loaded, do nothing.
  * 	All data in translation array are stored in UTF-8 format.
  *  tab_loaded is completed with $domain key.
  *  Value for hash are: 1:Loaded from disk, 2:Not found, 3:Loaded from cache
  *  @param      domain      		File name to load (.lang file). Use file@module if file is in a module directory.
  *  @param      alt         		0 (try xx_ZZ then 1), 1 (try xx_XX then 2), 2 (try en_US or fr_FR or es_ES)
  * 	@param		stopafterdirection	Stop when the DIRECTION tag is found (optimize)
  * 	@param		forcelangdir		To force a lang directory
  *	@return		int					<0 if KO, 0 if already loaded, >0 if OK
  */
 function Load($domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = '')
 {
     global $conf;
     // Check parameters
     if (empty($domain)) {
         dol_print_error('', "Translate::Load ErrorWrongParameters");
         exit;
     }
     //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang);
     $newdomain = $domain;
     $modulename = '';
     // Search if module directory name is different of lang file name
     if (preg_match('/^([^@]+)?@([^@]+)$/i', $domain, $regs)) {
         $newdomain = !empty($regs[1]) ? $regs[1] : $regs[2];
         $modulename = !empty($regs[1]) ? $regs[2] : '';
     }
     // Check cache
     if (!empty($this->tab_loaded[$newdomain])) {
         //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain);
         return 0;
     }
     $fileread = 0;
     $langofdir = empty($forcelangdir) ? $this->defaultlang : $forcelangdir;
     // Redefine alt
     $langarray = explode('_', $langofdir);
     if ($alt < 1 && strtolower($langarray[0]) == strtolower($langarray[1])) {
         $alt = 1;
     }
     if ($alt < 2 && (strtolower($langofdir) == 'en_us' || strtolower($langofdir) == 'fr_fr' || strtolower($langofdir) == 'es_es')) {
         $alt = 2;
     }
     foreach ($this->dir as $searchdir) {
         // If $domain is "file@module" instead of "file" then we look for module lang file
         // in htdocs/custom/modules/mymodule/langs/code_CODE/file.lang
         // and in htdocs/mymodule/langs/code_CODE/file.lang for backward compatibility
         // instead of file htdocs/langs/code_CODE/filelang
         if (preg_match('/@/', $domain)) {
             $searchdir = $searchdir . "/" . (!empty($modulename) ? $modulename : $newdomain) . "/langs";
         } else {
             $searchdir = $searchdir . "/langs";
         }
         // Directory of translation files
         $scandir = $searchdir . "/" . $langofdir;
         $file_lang = $scandir . "/" . $newdomain . ".lang";
         $file_lang_osencoded = dol_osencode($file_lang);
         $filelangexists = is_file($file_lang_osencoded);
         //dol_syslog('Translate::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' file_lang='.$file_lang." => ".$filelangexists);
         if ($filelangexists) {
             $found = false;
             // Enable cache of lang file in memory (not by default)
             $usecachekey = '';
             // Using a memcached server
             if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) {
                 $usecachekey = $newdomain . '_' . $langofdir;
             } else {
                 if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && $conf->global->MAIN_OPTIMIZE_SPEED & 0x2) {
                     $usecachekey = $newdomain;
                 }
             }
             if ($usecachekey) {
                 require_once DOL_DOCUMENT_ROOT . "/lib/memory.lib.php";
                 $tmparray = dol_getcache($usecachekey);
                 if (is_array($tmparray) && sizeof($tmparray)) {
                     $this->tab_translate = array_merge($tmparray, $this->tab_translate);
                     // Already found values tab_translate overwrites duplicates
                     //print $newdomain."\n";
                     //var_dump($this->tab_translate);
                     if ($alt == 2) {
                         $fileread = 1;
                     }
                     $found = true;
                     // Found in dolibarr PHP cache
                 }
             }
             if (!$found) {
                 if ($fp = @fopen($file_lang, "rt")) {
                     if ($usecachekey) {
                         $tabtranslatedomain = array();
                     }
                     // To save lang content in cache
                     while ($line = fgets($fp, 4096)) {
                         if ($line[0] != "\n" && $line[0] != " " && $line[0] != "#") {
                             $tab = explode('=', $line, 2);
                             $key = trim($tab[0]);
                             //print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
                             if ((!empty($conf->global->MAIN_USE_CUSTOM_TRANSLATION) || empty($this->tab_translate[$key])) && isset($tab[1])) {
                                 $value = trim(preg_replace('/\\n/', "\n", $tab[1]));
                                 if ($key == 'CHARSET') {
                                     $this->charset_inputfile[$newdomain] = strtoupper($value);
                                     //print 'File '.$file_lang.' is declared to have format '.$this->charset_inputfile[$newdomain].'<br>';
                                 } elseif ($key == 'DIRECTION') {
                                     if ($alt < 2 || empty($this->tab_translate[$key])) {
                                         $this->tab_translate[$key] = $value;
                                         if ($stopafterdirection) {
                                             break;
                                         } else {
                                             if ($usecachekey) {
                                                 $tabtranslatedomain[$key] = $value;
                                             }
                                         }
                                     }
                                 } else {
                                     // On stocke toujours dans le tableau Tab en UTF-8
                                     if (empty($this->charset_inputfile[$newdomain]) || $this->charset_inputfile[$newdomain] == 'ISO-8859-1') {
                                         $value = utf8_encode($value);
                                     }
                                     //print 'XX'.$key;
                                     $this->tab_translate[$key] = $value;
                                     if ($usecachekey) {
                                         $tabtranslatedomain[$key] = $value;
                                     }
                                     // To save lang content in cache
                                 }
                             }
                         }
                     }
                     fclose($fp);
                     $fileread = 1;
                     // To save lang content for usecachekey into cache
                     if ($usecachekey && sizeof($tabtranslatedomain)) {
                         require_once DOL_DOCUMENT_ROOT . "/lib/memory.lib.php";
                         $size = dol_setcache($usecachekey, $tabtranslatedomain);
                     }
                     if (empty($conf->global->MAIN_FORCELANGDIR) && empty($conf->global->MAIN_USE_CUSTOM_TRANSLATION)) {
                         break;
                     }
                     // Break loop on each root dir. If a module has forced dir, we do not stop loop.
                 }
             }
         }
     }
     // Now we complete with next file
     if ($alt == 0) {
         // This function MUST NOT contains call to syslog
         //dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG);
         $langofdir = strtolower($langarray[0]) . '_' . strtoupper($langarray[0]);
         $this->load($domain, $alt + 1, $stopafterdirection, $langofdir);
     }
     // Now we complete with reference en_US/fr_FR/es_ES file
     if ($alt == 1) {
         // This function MUST NOT contains call to syslog
         //dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG);
         $langofdir = 'en_US';
         if (preg_match('/^fr/i', $langarray[0])) {
             $langofdir = 'fr_FR';
         }
         if (preg_match('/^es/i', $langarray[0])) {
             $langofdir = 'es_ES';
         }
         $this->load($domain, $alt + 1, $stopafterdirection, $langofdir);
     }
     if ($alt == 2) {
         if ($fileread) {
             $this->tab_loaded[$newdomain] = 1;
         }
         // Set domain file as loaded
         if (empty($this->tab_loaded[$newdomain])) {
             $this->tab_loaded[$newdomain] = 2;
         }
         // Marque ce fichier comme non trouve
     }
     // Check to be sure that SeparatorDecimal differs from SeparatorThousand
     if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) {
         $this->tab_translate["SeparatorThousand"] = '';
     }
     return 1;
 }
Пример #7
0
 /**
  *  Load translation key-value from database into a memory array.
  *  If data already loaded, do nothing.
  * 	All data in translation array are stored in UTF-8 format.
  *  tab_loaded is completed with $domain key.
  *  rule "we keep first entry found with we keep last entry found" so it is probably not what you want to do.
  *
  *  Value for hash are: 1:Loaded from disk, 2:Not found, 3:Loaded from cache
  *
  *  @param  Database    $db             Database handler
  *	@return	int							<0 if KO, 0 if already loaded or loading not required, >0 if OK
  */
 function loadFromDatabase($db)
 {
     global $conf;
     $domain = 'database';
     if ($this->defaultlang == 'none_NONE') {
         return 0;
     }
     // Special language code to not translate keys
     // Check parameters
     if (empty($db)) {
         return 0;
     }
     // Database handler can't be used
     //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang);
     $newdomain = $domain;
     $modulename = '';
     // Check cache
     if (!empty($this->_tab_loaded[$newdomain])) {
         //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain);
         return 0;
     }
     $this->_tab_loaded[$newdomain] = 1;
     // We want to be sure this function is called once only.
     $fileread = 0;
     $langofdir = empty($forcelangdir) ? $this->defaultlang : $forcelangdir;
     // Redefine alt
     $alt = 2;
     if (empty($langofdir)) {
         dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
         return -1;
     }
     // TODO Move cache read out of loop on dirs or at least filelangexists
     $found = false;
     // Enable caching of lang file in memory (not by default)
     $usecachekey = '';
     // Using a memcached server
     if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) {
         $usecachekey = $newdomain . '_' . $langofdir . '_' . md5($file_lang);
         // Should not contains special chars
     } else {
         if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && $conf->global->MAIN_OPTIMIZE_SPEED & 0x2) {
             $usecachekey = $newdomain;
         }
     }
     if ($usecachekey) {
         //dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey);
         //global $aaa; $aaa+=1;
         //print $aaa." ".$usecachekey."\n";
         require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
         $tmparray = dol_getcache($usecachekey);
         if (is_array($tmparray) && count($tmparray)) {
             $this->tab_translate += $tmparray;
             // Faster than array_merge($tmparray,$this->tab_translate). Note: If a valuer already exists into tab_translate, value into tmparaay is not added.
             //print $newdomain."\n";
             //var_dump($this->tab_translate);
             if ($alt == 2) {
                 $fileread = 1;
             }
             $found = true;
             // Found in dolibarr PHP cache
         }
     }
     if (!$found) {
         // Overwrite translation with database read
         $sql = "SELECT transkey, transvalue FROM " . MAIN_DB_PREFIX . "overwrite_trans where lang='" . $this->defaultlang . "'";
         $resql = $db->query($sql);
         if ($resql) {
             $num = $db->num_rows($resql);
             if ($num) {
                 if ($usecachekey) {
                     $tabtranslatedomain = array();
                 }
                 // To save lang content in cache
                 $i = 0;
                 while ($i < $num) {
                     $obj = $db->fetch_object($resql);
                     $key = $obj->transkey;
                     $value = $obj->transvalue;
                     //print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>";
                     if (empty($this->tab_translate[$key])) {
                         $value = trim(preg_replace('/\\n/', "\n", $value));
                         $this->tab_translate[$key] = $value;
                         if ($usecachekey) {
                             $tabtranslatedomain[$key] = $value;
                         }
                         // To save lang content in cache
                     }
                     $i++;
                 }
                 $fileread = 1;
                 // TODO Move cache write out of loop on dirs
                 // To save lang content for usecachekey into cache
                 if ($usecachekey && count($tabtranslatedomain)) {
                     $ressetcache = dol_setcache($usecachekey, $tabtranslatedomain);
                     if ($ressetcache < 0) {
                         $error = 'Failed to set cache for usecachekey=' . $usecachekey . ' result=' . $ressetcache;
                         dol_syslog($error, LOG_ERR);
                     }
                 }
             }
         } else {
             dol_print_error($db);
         }
     }
     if ($alt == 2) {
         if ($fileread) {
             $this->_tab_loaded[$newdomain] = 1;
         }
         // Set domain file as loaded
         if (empty($this->_tab_loaded[$newdomain])) {
             $this->_tab_loaded[$newdomain] = 2;
         }
         // Marque ce cas comme non trouve (no lines found for language)
     }
     // Check to be sure that SeparatorDecimal differs from SeparatorThousand
     if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) {
         $this->tab_translate["SeparatorThousand"] = '';
     }
     return 1;
 }