function updateDb() { $params = array(); $toReturn = array(); $toReturn['updated'] = true; $toReturn['message'] = ""; $db = new RecordSet($this->dbConnectionInfo, false, true); $rows = $db->Open("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . $this->dbConnectionInfo['dbName'] . "' AND TABLE_NAME = 'webhelp'"); if ($rows > 0) { $db->Open("SELECT * FROM webhelp;"); while ($db->MoveNext()) { $assoc = $db->getAssoc(); $params[$db->Field("parameter")] = $db->Field("value"); } $db->Close(); if ($params['databaseVersion'] != '1') { $toReturn['updated'] = false; $toReturn['message'] = "Incompatible database version found!"; } } else { $toReturn['updated'] = false; $toReturn['message'] = "Database structure does not exist! In order to create a compatible database structure you must check option <strong>\"Create new database structure\"</strong> from previous instalation page."; } return $toReturn; }
/** * export Comments for a specified page * * @param IExporter $exporter exporter to be used * @param String fields to be exported separated by comma * @param String orderClause to be used in selecting records */ function export($exporter, $fields = null, $orderClause = null) { $whereClause = ""; $whereFromFilter = $exporter->getFilter()->getSqlFilterClause(); if ($whereFromFilter != null) { $whereClause = "WHERE " . $whereFromFilter; } $db = new RecordSet($this->dbConnectionInfo); $select = "*"; if ($fields != null) { //$select=Utils::arrayToString($fields,","); $select = $fields; } $sql = "SELECT " . $select . " FROM " . $this->tableName . " " . $whereClause; if ($orderClause != null) { $sql .= " " . $orderClause; } $sql .= ";"; if ($db->Open($sql)) { $rowArray = $db->getAssoc(); while ($rowArray) { if (is_array($rowArray)) { $exporter->exportRow($rowArray); } $rowArray = $db->getAssoc(); } } $db->Close(); }
function getBaseUrl($product, $version) { global $dbConnectionInfo; $toReturn = __BASE_URL__; $db = new RecordSet($dbConnectionInfo, false, true); $rows = $db->Open("SELECT value FROM webhelp WHERE parameter='path' AND product='" . $product . "' AND version='" . $version . "';"); if ($rows == 1) { $db->MoveNext(); $toReturn = $db->Field('value'); } $db->Close(); return $toReturn; }
/** * Obtaint all users to be notified when a new comment is inserted * * @param String $page page that is comment on * @param int $commentId new comment id * * @return array list of emails to be notified */ function getUsersToNotify($page, $commentId) { $toReturn = array(); $s_notifyAll = "SELECT userName FROM users WHERE notifyAll='yes' AND status ='validated';"; $db = new RecordSet($this->dbConnectionInfo); $db->Open($s_notifyAll); while ($db->MoveNext()) { $userName = $db->Field('userName'); if (!$this->isLdapUser($userName)) { $s_notify_local = "SELECT concat(name,' <',email,'> ') adrs FROM users WHERE userName = '******';"; $db2 = new RecordSet($this->dbConnectionInfo); $db2->Open($s_notify_local); $db2->MoveNext(); $toReturn[] = $db2->Field('adrs'); $db2->Close(); } else { $name = $this->getUserInformation($userName, LDAP_ACCOUNT_FULLNAME); $mail = $this->getUserInformation($userName, LDAP_ACCOUNT_EMAIL); if (strlen($mail) > 0) { $toReturn[] = $name . ' <' . $mail . '> '; } } } $s_notifyPage = "SELECT userName from users where notifyPage='yes' AND notifyAll='no'\r\n\t\tAND status ='validated' AND userId in (SELECT userId from comments where page='{$page}');"; $db->Open($s_notifyPage); while ($db->MoveNext()) { $userName = $db->Field('userName'); if (!$this->isLdapUser($userName)) { $s_notify_local = "SELECT concat(name,' <',email,'> ') adrs FROM users WHERE userName = '******';"; $db2 = new RecordSet($this->dbConnectionInfo); $db2->Open($s_notify_local); $db2->MoveNext(); if (!in_array($db2->Field('adrs'), $toReturn)) { $toReturn[] = $db2->Field('adrs'); } $db2->Close(); } else { $name = $this->getUserInformation($userName, LDAP_ACCOUNT_FULLNAME); $mail = $this->getUserInformation($userName, LDAP_ACCOUNT_EMAIL); $email = $name . ' <' . $mail . '> '; if (!in_array($email, $toReturn) && strlen($mail) > 0) { $toReturn[] = $email; } } } $r_comment = "SELECT referedComment FROM comments WHERE commentId='{$commentId}'"; $db->Open($r_comment); while ($db->MoveNext()) { if ($db->Field('referedComment') > 0) { $toReturn = $this->addUserToNotify($db->Field('referedComment'), $toReturn, $db); } } $db->Close(); return $toReturn; }
/** * Query all products and versions for existing comments */ function queryInfo() { $toReturn = array(); $db = new RecordSet($this->dbConnectionInfo); $query = "SELECT DISTINCT product,version FROM comments ORDER BY product;"; if ($db->Open($query) > 0) { while ($db->MoveNext()) { $toReturn[$db->Field('product')][] = $db->Field('version'); } } $db->Close(); return $toReturn; }
/** * Change password for an specified email with the specified one * * @param String $email user emai * @param String $password unencripted password * @return String user name */ function changePassword($email, $password) { $toReturn = ""; $db = new RecordSet($this->dbConnectionInfo); if ($password == $db->sanitize($password)) { $query = "UPDATE users SET password = '******' WHERE email='" . $email . "'"; $rows = $db->Run($query); if ($rows > 0) { $query = "SELECT userName FROM users WHERE email='" . $email . "'"; $db->Open($query); $db->MoveNext(); $toReturn = $db->Field("userName"); } } $db->Close(); return $toReturn; }
function installProduct($dbConnectionInfo) { global $productId, $productVersion; try { $db = new RecordSet($dbConnectionInfo, false, true); $db->Run("DELETE FROM webhelp WHERE parameter='path' AND product='" . $productId . "' AND version='" . $productVersion . "';"); $db->Run("DELETE FROM webhelp WHERE parameter='installDate' AND product='" . $productId . "' AND version='" . $productVersion . "';"); $db->Run("DELETE FROM webhelp WHERE parameter='dir' AND product='" . $productId . "' AND version='" . $productVersion . "';"); $db->Run("DELETE FROM webhelp WHERE parameter='name' AND product='" . $productId . "' AND version='" . $productVersion . "';"); $db->run("INSERT INTO `webhelp` (`parameter`, `value`, `product`, `version`) VALUES\n\t\t\t\t\t\t('installDate','" . date('YmdHis') . "','" . $productId . "','" . $productVersion . "'),\n\t\t\t\t\t\t\t('path','" . addslashes(Utils::getParam($_POST, 'baseUrl')) . "','" . $productId . "','" . $productVersion . "'),\n\t\t\t\t\t\t\t('dir','" . addslashes(dirname(dirname(__FILE__))) . "','" . $productId . "','" . $productVersion . "'),\n\t\t\t\t\t\t\t('name','" . addslashes(Utils::getParam($_POST, 'productName')) . "','" . $productId . "','" . $productVersion . "')\n\t\t\t\t\t\t\t;"); $db->Close(); } catch (Exception $e) { error_log("Exception installing product " . $productId . " version " . $productVersion . " details: " . $e->getMessage()); echo "Exception installing product " . $productId . " version " . $productVersion . " details: " . $e->getMessage(); throw $e; } }