public static function record($words, $found, $exact_match) { if (empty($words)) { return FALSE; } $insert = FALSE; $db = new PHPWS_DB('search_stats'); $word_count = count($words); foreach ($words as $keyword) { $db->resetWhere(); if (empty($keyword)) { continue; } $keyword = trim($keyword); $db->addWhere('keyword', $keyword); $stat = new Search_Stats(); $result = $db->loadObject($stat); if (empty($stat->keyword)) { $insert = TRUE; $stat->keyword = $keyword; } else { $insert = FALSE; } $stat->total_query++; if ($found) { $stat->query_success++; if ($exact_match) { $stat->exact_success++; } } else { $stat->query_failure++; } if ($word_count > 1) { $stat->mixed_query++; } if ($found > $stat->highest_result) { $stat->highest_result = $found; } $stat->last_called = time(); $stat->save($insert); } }
public function save() { if ($this->title != 'core') { $db = new PHPWS_DB('modules'); $db->addWhere('title', $this->title); $db->delete(); $db->resetWhere(); if (!$this->getProperName()) { $this->setProperName($this->getProperName(true)); } $result = $db->saveObject($this); if (PHPWS_Error::isError($result)) { return $result; } return $this->saveDependencies(); } else { $db = new PHPWS_DB('core_version'); $db->addValue('version', $this->version); $result = $db->update(); if (PHPWS_Error::isError($result)) { return $result; } } }
public static function pinBlockAll(Block_Item $block) { $values['block_id'] = $block->id; $db = new PHPWS_DB('block_pinned'); $db->addWhere($values); $result = $db->delete(); $db->resetWhere(); $values['key_id'] = -1; $db->addValue($values); return $db->insert(); }
public function viewImage($id, $view_folder = true) { Layout::addStyle('filecabinet'); PHPWS_Core::initModClass('filecabinet', 'Image.php'); $image = new PHPWS_Image($id); $folder = new Folder($image->folder_id); if (!$folder->allow()) { $content = dgettext('filecabinet', 'Sorry, the file you requested is off limits.'); Layout::add($content); return; } $tpl['TITLE'] = $image->title; if ($image->width > FC_MAX_IMAGE_POPUP_WIDTH || $image->height > FC_MAX_IMAGE_POPUP_HEIGHT) { if (FC_MAX_IMAGE_POPUP_WIDTH < FC_MAX_IMAGE_POPUP_HEIGHT) { $ratio = FC_MAX_IMAGE_POPUP_WIDTH / $image->width; $image->width = FC_MAX_IMAGE_POPUP_WIDTH; $image->height = $image->height * $ratio; } else { $ratio = FC_MAX_IMAGE_POPUP_HEIGHT / $image->height; $image->height = FC_MAX_IMAGE_POPUP_HEIGHT; $image->width = $image->width * $ratio; } $tpl['IMAGE'] = sprintf('<a href="%s">%s</a>', $image->getPath(), $image->getTag()); } else { $tpl['IMAGE'] = $image->getTag(); } $tpl['DESCRIPTION'] = $image->getDescription(); $tpl['CLOSE'] = javascript('close_window'); if ($view_folder && $folder->public_folder) { $db = new PHPWS_DB('images'); $db->setLimit(1); $db->addWhere('folder_id', $image->folder_id); $db->addWhere('title', $image->title, '>'); $db->addOrder('title'); $next_img = $db->getObjects('PHPWS_Image'); if (!empty($next_img)) { $next_link = Icon::show('next', dgettext('filecabinet', 'Next image')); $tpl['NEXT'] = sprintf('<a id="next-link" href="%s%s">%s</a>', PHPWS_Core::getHomeHttp(), $next_img[0]->popupAddress(), $next_link); } $db->resetWhere(); $db->resetOrder(); $db->addWhere('folder_id', $image->folder_id); $db->addWhere('title', $image->title, '<'); $db->addOrder('title desc'); $prev_img = $db->getObjects('PHPWS_Image'); if (!empty($prev_img)) { $prev_link = Icon::show('previous', dgettext('filecabinet', 'Previous image')); $tpl['PREV'] = sprintf('<a id="prev-link" href="%s%s">%s</a>', PHPWS_Core::getHomeHttp(), $prev_img[0]->popupAddress(), $prev_link); } } $content = PHPWS_Template::process($tpl, 'filecabinet', 'image_view.tpl'); Layout::nakedDisplay($content); }
public function registerModule($module, &$content) { $content[] = dgettext('boost', 'Registering module to core.'); $db = new PHPWS_DB('modules'); $db->addWhere('title', $module->title); $db->delete(); $db->resetWhere(); if (!$module->getProperName()) { $module->setProperName($module->getProperName(true)); } $result = $module->save(); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); $content[] = dgettext('boost', 'An error occurred during registration.'); $content[] = dgettext('boost', 'Check your logs for more information.'); } else { $content[] = dgettext('boost', 'Registration successful.'); if ($module->isRegister()) { $selfselfResult = $this->registerModToMod($module, $module, $content); $otherResult = $this->registerOthersToSelf($module, $content); } $selfResult = $this->registerSelfToOthers($module, $content); } $filename = sprintf('%smod/%s/inc/key.php', PHPWS_SOURCE_DIR, $module->title); if (is_file($filename)) { $content[] = dgettext('boost', 'Registered to Key.'); Key::registerModule($module->title); } $content[] = '<br />'; return $result; }
public function getAllSlots($bare = false, $search = null) { PHPWS_Core::initModClass('signup', 'Slots.php'); $db = new PHPWS_DB('signup_slots'); $db->addOrder('s_order'); $db->addWhere('sheet_id', $this->id); $db->setDistinct('true'); // Prevents a slot from showing up multiple times in the results if ($search) { $db->addWhere('id', 'signup_peeps.slot_id'); // Limits results to only Slots containing the search query $db->addWhere('signup_peeps.sheet_id', $this->id); $db->addWhere('signup_peeps.first_name', "{$search}%", 'like', 'and', 'search'); $db->addWhere('signup_peeps.last_name', "{$search}%", 'like', 'or', 'search'); } if ($bare) { $db->addColumn('id'); $db->addColumn('title'); $db->setIndexBy('id'); return $db->select('col'); } else { $result = $db->getObjects('Signup_Slot'); if (empty($result) || PHPWS_Error::logIfError($result)) { return null; } $db = new PHPWS_DB('signup_peeps'); $db->addColumn('id', null, null, true); foreach ($result as $slot) { $db->addWhere('slot_id', $slot->id); $db->addWhere('registered', 1); $sub = $db->select('one'); $db->resetWhere(); if (!PHPWS_Error::logIfError($sub)) { $slot->_filled = $sub; } } } return $result; }
public static function registerModule($module, &$content) { PHPWS_Core::initModClass('controlpanel', 'Tab.php'); PHPWS_Core::initModClass('controlpanel', 'Link.php'); $cpFile = sprintf('%smod/%s/boost/controlpanel.php', PHPWS_SOURCE_DIR, $module); if (!is_file($cpFile)) { PHPWS_Boost::addLog($module, dgettext('controlpanel', 'Control Panel file not implemented.')); return false; } include $cpFile; // insure cp file does not change translation directory if (isset($tabs) && is_array($tabs)) { foreach ($tabs as $info) { $tab = new PHPWS_Panel_Tab(); if (!isset($info['id'])) { $tab->setId(strtolower(preg_replace('/\\W/', '_', $info['title']))); } else { $tab->setId($info['id']); } if (!isset($info['title'])) { $content[] = dgettext('controlpanel', 'Unable to create tab.') . ' ' . dgettext('controlpanel', 'Missing title.'); continue; } $tab->setTitle($info['title']); if (!isset($info['link'])) { $content[] = dgettext('controlpanel', 'Unable to create tab.') . ' ' . dgettext('controlpanel', 'Missing link.'); continue; } $tab->setLink($info['link']); if (isset($info['itemname'])) { $tab->setItemname($info['itemname']); } else { $tab->setItemname('controlpanel'); } $result = $tab->save(); if (PHPWS_Error::isError($result)) { $content[] = dgettext('controlpanel', 'An error occurred when trying to save a controlpanel tab.'); PHPWS_Error::log($result); return false; } } $content[] = sprintf(dgettext('controlpanel', 'Control Panel tabs created for %s.'), $module); } else { PHPWS_Boost::addLog($module, dgettext('controlpanel', 'Control Panel tabs not implemented.')); } if (isset($link) && is_array($link)) { $db = new PHPWS_DB('controlpanel_tab'); foreach ($link as $info) { $modlink = new PHPWS_Panel_Link(); if (isset($info['label'])) { $modlink->setLabel($info['label']); } if (isset($info['restricted'])) { $modlink->setRestricted($info['restricted']); } elseif (isset($info['admin'])) { $modlink->setRestricted($info['admin']); } $modlink->setUrl($info['url']); $modlink->setActive(1); if (isset($info['itemname'])) { $modlink->setItemName($info['itemname']); } else { $modlink->setItemName($module); } $modlink->setDescription($info['description']); if (is_string($info['image'])) { $modlink->setImage($info['image']); } elseif (is_array($info['image'])) { $modlink->setImage($info['image']['name']); } $db->addWhere('id', $info['tab']); $db->addColumn('id'); $result = $db->select('one'); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); continue; } elseif (!isset($result)) { $tab_id = 'unsorted'; PHPWS_Boost::addLog($module, dgettext('controlpanel', 'Unable to load a link into a specified tab.')); } else { $tab_id = $info['tab']; } $modlink->setTab($tab_id); $result = $modlink->save(); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); $content[] = dgettext('controlpanel', 'There was a problem trying to save a Control Panel link.'); return false; } $db->resetWhere(); } $content[] = sprintf(dgettext('controlpanel', 'Control Panel links created for %s.'), $module); } else { PHPWS_Boost::addLog($module, dgettext('controlpanel', 'No Control Panel links found.')); } PHPWS_ControlPanel::reset(); return true; }
public function save() { $db = new PHPWS_DB('controlpanel_tab'); $db->addWhere('id', $this->id); $db->delete(); $db->resetWhere(); $this->tab_order = $this->getOrder(); return $db->saveObject($this, false, false); }
public function execute() { if (!isset($this->term) || is_null($this->term)) { throw new InvalidArgumentException('Missing term.'); } $sem = Term::getTermSem($this->term); switch ($sem) { case TERM_FALL: $db = new PHPWS_DB('hms_fall_application'); $db->addJoin('LEFT OUTER', 'hms_fall_application', 'hms_new_application', 'id', 'id'); break; case TERM_SPRING: $db = new PHPWS_DB('hms_spring_application'); $db->addJoin('LEFT OUTER', 'hms_spring_application', 'hms_new_application', 'id', 'id'); break; case TERM_SUMMER1: case TERM_SUMMER2: $db = new PHPWS_DB('hms_summer_application'); $db->addJoin('LEFT OUTER', 'hms_summer_application', 'hms_new_application', 'id', 'id'); break; } $db->addColumn('hms_new_application.*'); // Only applications for the selected term $db->addWhere('hms_new_application.term', $this->term); // Only non-cancelled applications $db->addWhere('hms_new_application.cancelled', 0); $results = $db->select(); if (PHPWS_Error::logIfError($results)) { throw new DatabaseException($results->toString()); } $types = array(TYPE_FRESHMEN, TYPE_TRANSFER, TYPE_CONTINUING, TYPE_NONDEGREE); $genders = array(MALE, FEMALE); // Initalize the array for totals foreach ($types as $t) { foreach ($genders as $g) { $this->applicationTotals[$t][$g] = 0; } } foreach ($genders as $g) { $this->cancelledTotals[$g] = 0; } // Calculate the sub-totals foreach ($results as $application) { // Adjust the student types to count 'readmit' and 'returning' as 'continuing' instead if ($application['student_type'] == TYPE_READMIT || $application['student_type'] == TYPE_RETURNING) { $studentType = TYPE_CONTINUING; } else { $studentType = $application['student_type']; } $this->applicationTotals[$studentType][$application['gender']]++; } // Male sub-total foreach ($types as $type) { $this->maleTotals[] = $this->applicationTotals[$type][MALE]; $this->maleSubTotal += $this->applicationTotals[$type][MALE]; } // Female sub-total foreach ($types as $type) { $this->femaleTotals[] = $this->applicationTotals[$type][FEMALE]; $this->femaleSubTotal += $this->applicationTotals[$type][FEMALE]; } // Type sums foreach ($types as $type) { $this->typeTotals[$type] = array_sum($this->applicationTotals[$type]); } // Sub-total $this->subTotal = $this->femaleSubTotal + $this->maleSubTotal; /**** * Count the cancelled applications */ $db->resetWhere(); // Only applications for the selected term $db->addWhere('hms_new_application.term', $this->term); // Only cancelled applications $db->addWhere('hms_new_application.cancelled', 1); $results = $db->select(); if (PHPWS_Error::logIfError($results)) { throw new DatabaseException($results->toString()); } foreach ($results as $application) { $this->cancelledTotals[$application['gender']]++; } // Cancelled sub-total $this->cancelledSubTotal = $this->cancelledTotals[FEMALE] + $this->cancelledTotals[MALE]; // Gender totals $this->maleGrandTotal = $this->maleSubTotal + $this->cancelledTotals[MALE]; $this->femaleGrandTotal = $this->femaleSubTotal + $this->cancelledTotals[FEMALE]; // Grand total $this->total = $this->subTotal + $this->cancelledSubTotal; }
public function saveLocalAuthorization() { if (empty($this->username) || empty($this->_password)) { return false; } $db = new PHPWS_DB('user_authorization'); if (!empty($this->_prev_username)) { $db->addWhere('username', $this->_prev_username); } else { $db->addWhere('username', $this->username); } $result = $db->delete(); $db->resetWhere(); $db->addValue('username', $this->username); $db->addValue('password', $this->_password); return $db->insert(); }
public static function postAuthorization() { if (isset($_POST['add_script'])) { if (!isset($_POST['file_list'])) { return false; } $db = new PHPWS_DB('users_auth_scripts'); $db->addWhere('filename', strip_tags($_POST['file_list'])); $result = $db->select('one'); if (PHPWS_Error::isError($result)) { return $result; } elseif (!empty($result)) { return false; } $db->resetWhere(); $db->addValue('display_name', $_POST['file_list']); $db->addValue('filename', $_POST['file_list']); $result = $db->insert(); if (PHPWS_Error::isError($result)) { return $result; } } else { if (isset($_POST['default_authorization'])) { PHPWS_Settings::set('users', 'default_authorization', (int) $_POST['default_authorization']); PHPWS_Settings::save('users'); } if (!empty($_POST['default_group'])) { $db = new PHPWS_DB('users_auth_scripts'); foreach ($_POST['default_group'] as $auth_id => $group_id) { $db->reset(); $db->addWhere('id', $auth_id); $db->addValue('default_group', $group_id); PHPWS_Error::logIfError($db->update()); } } } return true; }
public static function setPermissions($group_id, $module, $level, $subpermissions = NULL) { if (empty($group_id) || !is_numeric($group_id)) { return false; } $tableName = Users_Permission::getPermissionTableName($module); if (!PHPWS_DB::isTable($tableName)) { return; } $db = new PHPWS_DB($tableName); $db->addWhere('group_id', (int) $group_id); $db->delete(); $db->resetWhere(); $db->addValue('group_id', (int) $group_id); $columns = $db->getTableColumns(); $db->addValue('permission_level', (int) $level); if ($level == NO_PERMISSION) { unset($subpermissions); Users_Permission::clearItemPermissions($module, $group_id); } if (isset($subpermissions)) { foreach ($columns as $colName) { if ($colName == 'permission_level' || $colName == 'group_id') { continue; } if (isset($subpermissions[$colName]) && (int) $subpermissions[$colName] == 1) { $db->addValue($colName, 1); } else { $db->addValue($colName, 0); } } } return $db->insert(); }