/** * Fonction qui dit si cet utilisateur est un redacteur existant dans spip * @return int 1=existe, 0=n'existe pas, -1=erreur */ function is_in_spip() { if (defined("ADHERENT_USE_SPIP") && ADHERENT_USE_SPIP == 1 && defined('ADHERENT_SPIP_SERVEUR') && ADHERENT_SPIP_SERVEUR != '' && defined('ADHERENT_SPIP_USER') && ADHERENT_SPIP_USER != '' && defined('ADHERENT_SPIP_PASS') && ADHERENT_SPIP_PASS != '' && defined('ADHERENT_SPIP_DB') && ADHERENT_SPIP_DB != '') { $query = "SELECT login FROM spip_auteurs WHERE login='******'"; $mydb = new DoliDb('mysql', ADHERENT_SPIP_SERVEUR, ADHERENT_SPIP_USER, ADHERENT_SPIP_PASS, ADHERENT_SPIP_DB, ADHERENT_SPIP_PORT); if ($mydb->ok) { $result = $mydb->query($query); if ($result) { if ($mydb->num_rows($result)) { # nous avons au moins une reponse $mydb->close($result); return 1; } else { # nous n'avons pas de reponse => n'existe pas $mydb->close($result); return 0; } } else { # error $this->error = $mydb->error(); return -1; } } else { $this->error = "Echec de connexion avec les identifiants " . ADHERENT_SPIP_SERVEUR . " " . ADHERENT_SPIP_USER . " " . ADHERENT_SPIP_PASS . " " . ADHERENT_SPIP_DB; return -1; } } }
// $conf is already instancied inside inc.php $conf->db->type = $dolibarr_main_db_type; $conf->db->host = $dolibarr_main_db_host; $conf->db->port = $dolibarr_main_db_port; $conf->db->name = $dolibarr_main_db_name; $conf->db->user = $dolibarr_main_db_user; $conf->db->pass = $dolibarr_main_db_pass; // Load type and crypt key if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0; $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey=''; $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port); if ($db->connected == 1) { print '<tr><td nowrap="nowrap">'; print $langs->trans("ServerConnection")." : $dolibarr_main_db_host</td><td align=\"right\">".$langs->trans("OK")."</td></tr>\n"; dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ServerConnection")." : $dolibarr_main_db_host ".$langs->transnoentities("OK")); $ok = 1; } else { print "<tr><td>".$langs->trans("ErrorFailedToConnectToDatabase",$dolibarr_main_db_name)."</td><td align=\"right\">".$langs->transnoentities("Error")."</td></tr>\n"; dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ErrorFailedToConnectToDatabase",$dolibarr_main_db_name)); $ok = 0; } if ($ok)
/** * Load all objects with filters * * @param DoliDb $db Database handler * @param int $socid Filter by thirdparty * @param int $fk_element Id of element action is linked to * @param string $elementtype Type of element action is linked to * @param string $filter Other filter * @param string $sortfield Sort on this field * @param string $sortorder ASC or DESC * @return array or string Error string if KO, array with actions if OK */ static function getActions($db, $socid = 0, $fk_element = 0, $elementtype = '', $filter = '', $sortfield = '', $sortorder = '') { global $conf, $langs; $resarray = array(); $sql = "SELECT a.id"; $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a"; $sql .= " WHERE a.entity IN (" . getEntity('actioncomm', 1) . ")"; if (!empty($socid)) { $sql .= " AND a.fk_soc = " . $socid; } if (!empty($elementtype)) { if ($elementtype == 'project') { $sql .= ' AND a.fk_project = ' . $fk_element; } else { $sql .= " AND a.fk_element = " . $fk_element . " AND a.elementtype = '" . $elementtype . "'"; } } if (!empty($filter)) { $sql .= $filter; } if ($sortorder && $sortfield) { $sql .= $db->order($sortfield, $sortorder); } dol_syslog(get_class() . "::getActions", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { for ($i = 0; $i < $num; $i++) { $obj = $db->fetch_object($resql); $actioncommstatic = new ActionComm($db); $actioncommstatic->fetch($obj->id); $resarray[$i] = $actioncommstatic; } } $db->free($resql); return $resarray; } else { return $db->lasterror(); } }
$dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass); $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass); $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted } else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass); } // $conf is already instancied inside inc.php $conf->db->type = $dolibarr_main_db_type; $conf->db->host = $dolibarr_main_db_host; $conf->db->port = $dolibarr_main_db_port; $conf->db->name = $dolibarr_main_db_name; $conf->db->user = $dolibarr_main_db_user; $conf->db->pass = $dolibarr_main_db_pass; $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port); if ($db->connected == 1) { print '<tr><td nowrap="nowrap">'; print $langs->trans("ServerConnection")." : $dolibarr_main_db_host</td><td align=\"right\">".$langs->trans("OK")."</td></tr>"; dolibarr_install_syslog("repair: ".$langs->transnoentities("ServerConnection")." : $dolibarr_main_db_host ".$langs->transnoentities("OK")); $ok = 1; } else { print "<tr><td>".$langs->trans("ErrorFailedToConnectToDatabase",$dolibarr_main_db_name)."</td><td align=\"right\">".$langs->transnoentities("Error")."</td></tr>"; dolibarr_install_syslog("repair: ".$langs->transnoentities("ErrorFailedToConnectToDatabase",$dolibarr_main_db_name)); $ok = 0; } if ($ok)
print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>'; print '</td></tr>'; $error++; } } } // Fin si "creation utilisateur" /* * If database creation is asked, we create it */ if (! $error && (isset($_POST["db_create_database"]) && $_POST["db_create_database"] == "on")) { dolibarr_install_syslog("etape1: Create database : ".$dolibarr_main_db_name, LOG_DEBUG); $db = new DoliDb($conf->db->type,$conf->db->host,$userroot,$passroot,'',$conf->db->port); if ($db->connected) { $result=$db->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user); if ($result) { print '<tr><td>'; print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : "; print $dolibarr_main_db_name; print '</td>'; print "<td>".$langs->trans("OK")."</td></tr>"; $check1=$db->getDefaultCharacterSetDatabase(); $check2=$db->getDefaultCollationDatabase();
// Test if we can run a first install process if (! is_writable($conffile)) { print $langs->trans("ConfFileIsNotWritable",$conffiletoshow); pFooter(1,$setuplang,'jscheckparam'); exit; } if ($action == "set") { print '<h3>'.$langs->trans("Database").'</h3>'; print '<table cellspacing="0" cellpadding="4" border="0" width="100%">'; $error=0; $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port); if ($db->connected == 1) { print "<tr><td>"; print $langs->trans("ServerConnection")." : ".$conf->db->host."</td><td>".$langs->trans("OK")."</td></tr>"; $ok = 1 ; } else { print "<tr><td>Failed to connect to server : ".$conf->db->host."</td><td>".$langs->trans("Error")."</td></tr>"; } if ($ok) { if($db->database_selected == 1) {
// Test if we can run a first install process if (! is_writable($conffile)) { print $langs->trans("ConfFileIsNotWritable",$conffiletoshow); pFooter(1,$setuplang,'jscheckparam'); exit; } print '<br>'.$langs->trans("LastStepDesc").'<br><br>'; print '<table cellspacing="0" cellpadding="2" width="100%">'; $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port); if ($db->ok == 1) { print '<tr><td>'.$langs->trans("DolibarrAdminLogin").' :</td><td>'; print '<input name="login" value="'.(! empty($_GET["login"])?$_GET["login"]:$force_install_dolibarrlogin).'"></td></tr>'; print '<tr><td>'.$langs->trans("Password").' :</td><td>'; print '<input type="password" name="pass"></td></tr>'; print '<tr><td>'.$langs->trans("PasswordAgain").' :</td><td>'; print '<input type="password" name="pass_verif"></td></tr>'; print '</table>'; if (isset($_GET["error"]) && $_GET["error"] == 1) { print '<br>'; print '<div class="error">'.$langs->trans("PasswordsMismatch").'</div>'; $err=0; // We show button
/** * Return nb of links * * @param DoliDb $db Database handler * @param string $objecttype Type of the associated object in dolibarr * @param int $objectid Id of the associated object in dolibarr * @return int Nb of links, -1 if error **/ public static function count($db, $objecttype, $objectid) { global $conf; $sql = "SELECT COUNT(rowid) as nb FROM " . MAIN_DB_PREFIX . "links"; $sql .= " WHERE objecttype = '" . $objecttype . "' AND objectid = " . $objectid; if ($conf->entity != 0) { $sql .= " AND entity = " . $conf->entity; } $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); if ($obj) { return $obj->nb; } } return -1; }
if (! $db->connected) print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>'; print $langs->trans("ErrorGoBackAndCorrectParameters"); $error++; } elseif ($db->error && ! (! empty($_POST["db_create_database"]) && $db->connected)) { print '<div class="error">'.$db->error.'</div>'; if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>'; print $langs->trans("ErrorGoBackAndCorrectParameters"); $error++; } } // If we need simple access if (! $error && (empty($_POST["db_create_database"]) && empty($_POST["db_create_user"]))) { $db = new DoliDb($_POST["db_type"],$_POST["db_host"],$_POST["db_user"],$_POST["db_pass"],$_POST["db_name"],$_POST["db_port"]); if ($db->error) { print '<div class="error">'.$db->error.'</div>'; if (! $db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>'; print $langs->trans("ErrorGoBackAndCorrectParameters"); $error++; } } } else { print "<br>\nFailed to include_once(\"".$main_dir."/lib/databases/".$_POST["db_type"].".lib.php\")<br>\n"; print '<div class="error">'.$langs->trans("ErrorWrongValueForParameter",$langs->transnoentities("WebPagesDirectory")).'</div>'; print $langs->trans("ErrorGoBackAndCorrectParameters"); $error++;