function fixUnits()
 {
     // First, assign the unit to a group directly on the group
     // table, not via the group_units table, since groups could only
     // belong to a single unit anyway.
     $sGULTable = KTUtil::getTableName("groups_units");
     $sGroupsTable = KTUtil::getTableName('groups');
     $aGroupUnits = DBUtil::getResultArray("SELECT group_id, unit_id FROM {$sGULTable}");
     foreach ($aGroupUnits as $aRow) {
         // $curunit = DBUtil::getOneResultKey(array("SELECT unit_id FROM $sGroupsTable WHERE id = ?", array($aRow['group_id'])), "unit_id");
         DBUtil::autoUpdate($sGroupsTable, array('unit_id' => $aRow['unit_id']), $aRow['group_id']);
     }
     // Now, assign the unit folder id to the unit directly, instead
     // of storing the unit_id on every folder beneath the unit
     // folder.
     $sFoldersTable = KTUtil::getTableName('folders');
     $sUnitsTable = KTUtil::getTableName('units');
     $sQuery = "SELECT id FROM folders WHERE unit_id = ? ORDER BY LENGTH(parent_folder_ids) LIMIT 1";
     $aUnitIds = DBUtil::getResultArrayKey("SELECT id FROM {$sUnitsTable}", 'id');
     foreach ($aUnitIds as $iUnitId) {
         $aParams = array($iUnitId);
         $iFolderId = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id');
         if (!empty($iFolderId)) {
             DBUtil::autoUpdate($sUnitsTable, array('folder_id' => $iFolderId), $iUnitId);
         }
     }
     return true;
 }
Exemple #2
0
function updateTask($aFieldValues, $iId)
{
    DBUtil::autoUpdate('scheduler_tasks', $aFieldValues, $iId);
}
 function do_resetPassword()
 {
     $email = $_REQUEST['email'];
     $user = $_REQUEST['username'];
     $password = $_REQUEST['password'];
     $confirm = $_REQUEST['confirm'];
     if (!($password == $confirm)) {
         return _kt('The passwords do not match, please re-enter them.');
     }
     $password = md5($password);
     // Get user from db
     $sQuery = 'SELECT id FROM users WHERE username = ? AND email = ?';
     $aParams = array($user, $email);
     $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id');
     if (!is_numeric($id) || $id < 1) {
         //PEAR::isError($res) || is_null($res)){
         return _kt('Please check that you have entered a valid username and email address.');
     }
     // Check expiry
     $expiry = KTUtil::getSystemSetting('password_reset_expire-' . $id);
     if ($expiry < time()) {
         return _kt('The password reset key has expired, please send a new request.');
     }
     // Update password
     $res = DBUtil::autoUpdate('users', array('password' => $password), $id);
     if (PEAR::isError($res) || is_null($res)) {
         return _kt('Your password could not be reset, please try again.');
     }
     // Unset expiry date and key
     KTUtil::setSystemSetting('password_reset_expire-' . $id, '');
     KTUtil::setSystemSetting('password_reset_key-' . $id, '');
     // Email confirmation
     $url = KTUtil::addQueryStringSelf('');
     $subject = APP_NAME . ': ' . _kt('password successfully reset');
     $body = '<dd><p>';
     $body .= _kt('Your password has been successfully reset, click the link below to login.');
     $body .= "</p><p><a href = '{$url}'>" . _kt('Login') . '</a></p></dd>';
     $oEmail = new Email();
     $res = $oEmail->send($email, $subject, $body);
     if ($res === true) {
         return _kt('Your password has been successfully reset.');
     }
     return _kt('An error occurred while sending the email, please try again or contact the System Administrator.');
 }
 /**
  * Update the position of a column
  */
 function updatePosition($iId, $position)
 {
     $aFields = array('position' => $position);
     DBUtil::autoUpdate('column_entries', $aFields, $iId);
 }
 /**
  * Save any modified settings, clear the cached settings and return the new settings
  *
  * @param array $currentSettings
  * @return array
  */
 function saveSettings($currentSettings, $log = false)
 {
     $newSettings = isset($_POST['configArray']) ? $_POST['configArray'] : '';
     if (!empty($newSettings)) {
         $this->addInfoMessage(_kt('The configuration settings have been updated.'));
         if ($log) {
             $comment = array();
         }
         // If the value in the post array is different from the current value, then update the DB
         foreach ($currentSettings as $setting) {
             $new = $newSettings[$setting['id']];
             if ($setting['value'] != $new) {
                 // Update the value
                 $res = DBUtil::autoUpdate('config_settings', array('value' => $new), $setting['id']);
                 if (PEAR::isError($res)) {
                     $this->addErrorMessage(sprintf(_kt("The setting %s could not be updated: %s"), $setting['display_name'], $res->getMessage()));
                 }
                 if ($log) {
                     $comment[] = sprintf(_kt("%s from %s to %s"), $setting['display_name'], $setting['value'], $new);
                 }
             }
         }
         if ($log) {
             $this->logTransaction($comment);
         }
         // Clear the cached settings
         $oKTConfig = new KTConfig();
         $oKTConfig->clearCache();
         // Get the new settings from the DB
         $currentSettings = $this->getSettings();
     }
     return $currentSettings;
 }
 /**
  * Register the plugin in the DB
  *
  * @param unknown_type $sClassName
  * @param unknown_type $path
  * @param unknown_type $object
  * @param unknown_type $type
  */
 function registerPluginHelper($sNamespace, $sClassName, $path, $object, $view, $type)
 {
     $sql = "SELECT id FROM plugin_helper WHERE namespace = '{$sNamespace}' AND classtype = '{$type}'";
     $res = DBUtil::getOneResult($sql);
     $aValues = array();
     $aValues['namespace'] = $sNamespace;
     $aValues['plugin'] = !empty($this->sNamespace) ? $this->sNamespace : $sNamespace;
     $aValues['classname'] = $sClassName;
     $aValues['pathname'] = $path;
     $aValues['object'] = $object;
     $aValues['viewtype'] = $view;
     $aValues['classtype'] = $type;
     // if record exists - update it.
     if (!empty($res)) {
         $id = $res['id'];
         $updateRes = DBUtil::autoUpdate('plugin_helper', $aValues, $id);
         if (PEAR::isError($updateRes)) {
             return $updateRes;
         }
         return true;
     }
     // Insert into DB
     $res = DBUtil::autoInsert('plugin_helper', $aValues);
     if (PEAR::isError($res)) {
         return $res;
     }
     return true;
 }
 function copy($oDocument, $oDestinationFolder, $sReason = null, $sDestinationDocName = null)
 {
     // 1. generate a new triad of content, metadata and core objects.
     // 2. update the storage path.
     //print '--------------------------------- BEFORE';
     //print_r($oDocument);
     // TODO: this is not optimal. we have get() functions that will do SELECT when we already have the data in arrays
     // get the core record to be copied
     $sDocumentTable = KTUtil::getTableName('documents');
     $sQuery = 'SELECT * FROM ' . $sDocumentTable . ' WHERE id = ?';
     $aParams = array($oDocument->getId());
     $aCoreRow = DBUtil::getOneResult(array($sQuery, $aParams));
     // we unset the id as a new one will be created on insert
     unset($aCoreRow['id']);
     // get a copy of the latest metadata version for the copied document
     $iOldMetadataId = $aCoreRow['metadata_version_id'];
     $sMetadataTable = KTUtil::getTableName('document_metadata_version');
     $sQuery = 'SELECT * FROM ' . $sMetadataTable . ' WHERE id = ?';
     $aParams = array($iOldMetadataId);
     $aMDRow = DBUtil::getOneResult(array($sQuery, $aParams));
     // we unset the id as a new one will be created on insert
     unset($aMDRow['id']);
     // set the name for the document, possibly using name collission
     if (empty($sDestinationDocName)) {
         $aMDRow['name'] = KTDocumentUtil::getUniqueDocumentName($oDestinationFolder, $aMDRow['name']);
     } else {
         $aMDRow['name'] = $sDestinationDocName;
     }
     // get a copy of the latest content version for the copied document
     $iOldContentId = $aMDRow['content_version_id'];
     $sContentTable = KTUtil::getTableName('document_content_version');
     $sQuery = 'SELECT * FROM ' . $sContentTable . ' WHERE id = ?';
     $aParams = array($iOldContentId);
     $aContentRow = DBUtil::getOneResult(array($sQuery, $aParams));
     // we unset the id as a new one will be created on insert
     unset($aContentRow['id']);
     // set the filename for the document, possibly using name collission
     if (empty($sDestinationDocName)) {
         $aContentRow['filename'] = KTDocumentUtil::getUniqueFilename($oDestinationFolder, $aContentRow['filename']);
     } else {
         $aContentRow['filename'] = $sDestinationDocName;
     }
     // create the new document record
     $aCoreRow['modified'] = date('Y-m-d H:i:s');
     $aCoreRow['folder_id'] = $oDestinationFolder->getId();
     // new location.
     $id = DBUtil::autoInsert($sDocumentTable, $aCoreRow);
     if (PEAR::isError($id)) {
         return $id;
     }
     $iNewDocumentId = $id;
     // create the new metadata record
     $aMDRow['document_id'] = $iNewDocumentId;
     $aMDRow['description'] = $aMDRow['name'];
     $id = DBUtil::autoInsert($sMetadataTable, $aMDRow);
     if (PEAR::isError($id)) {
         return $id;
     }
     $iNewMetadataId = $id;
     // the document metadata version is still pointing to the original
     $aCoreUpdate = array();
     $aCoreUpdate['metadata_version_id'] = $iNewMetadataId;
     $aCoreUpdate['metadata_version'] = 0;
     // create the new content version
     $aContentRow['document_id'] = $iNewDocumentId;
     $id = DBUtil::autoInsert($sContentTable, $aContentRow);
     if (PEAR::isError($id)) {
         return $id;
     }
     $iNewContentId = $id;
     // the metadata content version is still pointing to the original
     $aMetadataUpdate = array();
     $aMetadataUpdate['content_version_id'] = $iNewContentId;
     $aMetadataUpdate['metadata_version'] = 0;
     // apply the updates to the document and metadata records
     $res = DBUtil::autoUpdate($sDocumentTable, $aCoreUpdate, $iNewDocumentId);
     if (PEAR::isError($res)) {
         return $res;
     }
     $res = DBUtil::autoUpdate($sMetadataTable, $aMetadataUpdate, $iNewMetadataId);
     if (PEAR::isError($res)) {
         return $res;
     }
     // now, we have a semi-sane document object. get it.
     $oNewDocument = Document::get($iNewDocumentId);
     //print '--------------------------------- AFTER';
     //print_r($oDocument);
     //print '======';
     //print_r($oNewDocument);
     // copy the metadata from old to new.
     $res = KTDocumentUtil::copyMetadata($oNewDocument, $iOldMetadataId);
     if (PEAR::isError($res)) {
         return $res;
     }
     // Ensure the copied document is not checked out
     $oNewDocument->setIsCheckedOut(false);
     $oNewDocument->setCheckedOutUserID(-1);
     // finally, copy the actual file.
     $oStorage =& KTStorageManagerUtil::getSingleton();
     $res = $oStorage->copy($oDocument, $oNewDocument);
     $oOriginalFolder = Folder::get($oDocument->getFolderId());
     $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId();
     $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId();
     if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) {
         $oNewDocument->setPermissionObjectId($oDestinationFolder->getPermissionObjectId());
     }
     $res = $oNewDocument->update();
     if (PEAR::isError($res)) {
         return $res;
     }
     KTPermissionUtil::updatePermissionLookup($oNewDocument);
     if (is_null($sReason)) {
         $sReason = '';
     }
     $oDocumentTransaction = new DocumentTransaction($oDocument, sprintf(_kt("Copied to folder \"%s\". %s"), $oDestinationFolder->getName(), $sReason), 'ktcore.transactions.copy');
     $oDocumentTransaction->create();
     $oSrcFolder = Folder::get($oDocument->getFolderID());
     $oDocumentTransaction = new DocumentTransaction($oNewDocument, sprintf(_kt("Copied from original in folder \"%s\". %s"), $oSrcFolder->getName(), $sReason), 'ktcore.transactions.copy');
     $oDocumentTransaction->create();
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('copyDocument', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array('document' => $oNewDocument, 'old_folder' => $oSrcFolder, 'new_folder' => $oDestinationFolder);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
         if (PEAR::isError($ret)) {
             return $ret;
         }
     }
     // fire subscription alerts for the copied document
     $oSubscriptionEvent = new SubscriptionEvent();
     $oFolder = Folder::get($oDocument->getFolderID());
     $oSubscriptionEvent->MoveDocument($oDocument, $oDestinationFolder, $oSrcFolder, 'CopiedDocument');
     return $oNewDocument;
 }