public function setTabs($tabs) { if (!is_array($tabs)) { return PHPWS_Error::get(CP_BAD_TABS, 'controlpanel', 'setTabs'); } $this->tabs =& $tabs; }
public function setTable($table) { if (!PHPWS_DB::isTable($table)) { return PHPWS_Error::get(PHPWS_DB_NO_TABLE, 'core', __CLASS__ . '::' . __FUNCTION__); } $this->table = $table; return TRUE; }
/** * @version $Id$ * @author Adam Morton * @author Steven Levin */ function archive($formId = NULL) { if (!isset($formId)) { $message = dgettext('phatform', 'No form ID was passed'); return new PHPWS_Error('phatform', 'archive()', $message, 'continue', PHAT_DEBUG_MODE); } $archiveDir = PHPWS_HOME_DIR . 'files/phatform/archive/'; $path = $archiveDir; clearstatcache(); if (!is_dir($path)) { if (is_writeable($archiveDir)) { PHPWS_File::makeDir($path); } else { return PHPWS_Error::get(PHATFORM_ARCHIVE_PATH, 'phatform', 'Archive.php::archive', $path); } } else { if (!is_writeable($path)) { return PHPWS_Error::get(PHATFORM_ARCHIVE_PATH, 'phatform', 'Archive.php::archive()'); } } $table = array(); $time = time(); $table[] = 'mod_phatform_forms'; $table[] = 'mod_phatform_forms_seq'; $table[] = 'mod_phatform_form_' . $formId; $table[] = 'mod_phatform_form_' . $formId . '_seq'; $table[] = 'mod_phatform_multiselect'; $table[] = 'mod_phatform_multiselect_seq'; $table[] = 'mod_phatform_checkbox'; $table[] = 'mod_phatform_checkbox_seq'; $table[] = 'mod_phatform_dropbox'; $table[] = 'mod_phatform_dropbox_seq'; $table[] = 'mod_phatform_options'; $table[] = 'mod_phatform_options_seq'; $table[] = 'mod_phatform_radiobutton'; $table[] = 'mod_phatform_radiobutton_seq'; $table[] = 'mod_phatform_textarea'; $table[] = 'mod_phatform_textarea_seq'; $table[] = 'mod_phatform_textfield'; $table[] = 'mod_phatform_textfield_seq'; $step1 = explode('//', PHPWS_DSN); $step2 = explode('@', $step1[1]); $step3 = explode(':', $step2[0]); $step4 = explode('/', $step2[1]); $dbuser = $step3[0]; $dbpass = $step3[1]; $dbhost = $step4[0]; $dbname = $step4[1]; for ($i = 0; $i < sizeof($table); $i++) { $pipe = ' >> '; if ($i == 0) { $pipe = ' > '; } $goCode = 'mysqldump -h' . $dbhost . ' -u' . $dbuser . ' -p' . $dbpass . ' ' . $dbname . ' ' . $table[$i] . $pipe . $path . $formId . '.' . $time . '.phat'; system($goCode); } }
public static function write($name, $value, $time = 0) { if (empty($time)) { $time = time() + 31536000; } $time = (int) $time; $cookie_index = sprintf('%s[%s]', COOKIE_HASH, $name); if (!setcookie($cookie_index, $value, $time)) { return PHPWS_Error::get(COOKIE_SET_FAILED, 'core', 'PHPWS_Cookie::write'); } }
/** * Saves the cache content * @param string key Name of cache key. * @param string content Content stored in the cache * @returns boolean TRUE on success, FALSE otherwise */ public static function save($key, $content) { $key .= SITE_HASH . \Settings::get('Global', 'language'); if (!PHPWS_Cache::isEnabled()) { return; } if (!is_string($content)) { return PHPWS_Error::get(PHPWS_VAR_TYPE, 'core', __CLASS__ . '::' . __FUNCTION__); } $cache = PHPWS_Cache::initCache(); return $cache->save($content, md5($key)); }
public function userOption($module_title) { $module = new PHPWS_Module($module_title); $directory = $module->getDirectory(); $final_file = $directory . 'inc/my_page.php'; if (!is_file($final_file)) { PHPWS_Error::log(PHPWS_FILE_NOT_FOUND, 'users', 'userOption', $final_file); return dgettext('users', 'There was a problem with this module\'s My Page file.'); } include $final_file; if (!function_exists('my_page')) { return PHPWS_Error::get(USER_MISSING_MY_PAGE, 'users', 'My_Page::userOption', $module_title); } $content = my_page(); return $content; }
public function parse($xml_file, $die_on_error = true) { $file_contents = @file($xml_file); if (empty($file_contents)) { return PHPWS_Error::get(PHPWS_FILE_NOT_FOUND, 'core', 'XMLParser:parse', $xml_file); } foreach ($file_contents as $data) { $parse = xml_parse($this->xml, $data); if (!$parse) { if ($die_on_error) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xml)), xml_get_current_line_number($this->xml))); xml_parser_free($this->xml); } else { return PHPWS_Error::get(PHPWS_WRONG_TYPE, 'core', 'XMLParset:parse', $xml_file); } } } return true; }
/** * Set operator after checking for compatibility * addWhere strtouppers the operator */ public function setOperator($operator) { if (empty($operator)) { return false; } if (!PHPWS_DB::checkOperator($operator)) { return PHPWS_Error::get(PHPWS_DB_BAD_OP, 'core', 'PHPWS_DB::addWhere', _('DB Operator:') . $operator); } if ($operator == 'LIKE' || $operator == 'ILIKE') { $operator = $GLOBALS['PHPWS_DB']['lib']->getLike(); } elseif ($operator == 'NOT LIKE' || $operator == 'NOT ILIKE') { $operator = 'NOT ' . $GLOBALS['PHPWS_DB']['lib']->getLike(); } elseif ($operator == '~' || $operator == '~*' || $operator == 'REGEXP' || $operator == 'RLIKE') { $operator = $GLOBALS['PHPWS_DB']['lib']->getRegexp(); } elseif ($operator == '!~' || $operator == '!~*' || $operator == 'NOT REGEXP' || $operator == 'NOT RLIKE') { $operator = $GLOBALS['PHPWS_DB']['lib']->getNotRegexp(); } $this->operator = $operator; }
public function loadTemplate() { PHPWS_Core::initCoreClass('XMLParser.php'); $xml = new XMLParser($this->file); $xml->setContentOnly(true); if (PHPWS_Error::isError($xml->error)) { return $xml->error; } $result = $xml->format(); if (empty($result['TEMPLATE'])) { return; } $this->data = $result['TEMPLATE']; if (!isset($this->data['TITLE'])) { $this->error[] = PHPWS_Error::get(PS_TPL_NO_TITLE, 'pagesmith', 'PS_Template::loadTemplate', $this->name); return; } $this->title =& $this->data['TITLE']; if (isset($this->data['SUMMARY'])) { $this->summary =& $this->data['SUMMARY']; } if (empty($this->data['THUMBNAIL'])) { $this->error[] = PHPWS_Error::get(PS_TPL_NO_TN, 'pagesmith', 'PS_Template::loadTemplate', $this->name); return; } $this->thumbnail =& $this->data['THUMBNAIL']; if (isset($this->data['STYLE'])) { $this->style =& $this->data['STYLE']; } if (empty($this->data['STRUCTURE']['SECTION'])) { $this->error[] = PHPWS_Error::get(PS_TPL_NO_SECTIONS, 'pagesmith', 'PS_Template::loadTemplate', $this->name); return; } $this->structure =& $this->data['STRUCTURE']['SECTION']; if (isset($this->data['FOLDERS'])) { if (is_array($this->data['FOLDERS']['NAME'])) { $this->folders =& $this->data['FOLDERS']['NAME']; } else { $this->folders = array($this->data['FOLDERS']['NAME']); } } }
public function save() { if (!$this->sheet_id) { return PHPWS_Error::get(SU_NO_SHEET_ID, 'signup', 'Signup_Slot::save'); } $db = new PHPWS_DB('signup_slots'); if (!$this->id) { $db->addWhere('sheet_id', $this->sheet_id); $db->addColumn('s_order', 'max'); $max = $db->select('one'); if (PHPWS_Error::isError($max)) { return $max; } if ($max >= 1) { $this->s_order = $max + 1; } else { $this->s_order = 1; } $db->reset(); } return $db->saveObject($this); }
/** * Save this PHAT_Radiobutton * * @return mixed Content if going to getOptions stage, content for edit if first form not filled in properly, * or PHPWS_Error on failure. * @access public */ function save() { $error = FALSE; $label = $this->getLabel(); if (!$_SESSION['PHAT_FormManager']->form->checkLabel($_REQUEST['PHAT_ElementName']) && strcasecmp($label, $_REQUEST['PHAT_ElementName']) != 0 || PHPWS_Error::isError($this->setLabel(PHPWS_DB::sqlFriendlyName($_REQUEST['PHAT_ElementName'])))) { $currentError = PHPWS_Error::get(PHATFORM_INVALID_NAME, 'phatform', 'PHAT_Radiobutton::save()'); $error = TRUE; } $result = $this->setBlurb($_REQUEST['PHAT_ElementBlurb']); if (PHPWS_Error::isError($result)) { $currentError = $result; $error = TRUE; } if (isset($_REQUEST['PHAT_ElementRequired'])) { $this->setRequired(TRUE); } else { $this->setRequired(FALSE); } if ($error) { return $currentError; } else { if (is_numeric($_REQUEST['PHAT_ElementNumOptions']) && $_REQUEST['PHAT_ElementNumOptions'] > 0 || isset($_REQUEST['PHAT_OptionSet'])) { return $this->getOptions(); } else { return PHPWS_Error::get(PHATFORM_ZERO_OPTIONS, 'phatform', 'PHAT_Radiobutton::save()'); } } }
/** * added limitations to a select query to only pull rows that * the user is allowed to see. This function does does not work alone. * it requires a database object to already be started. * * The user module MUST be active for this function to work. * This Key function cannot be called without it. * * If the user is a deity or an unrestricted user, no change will be made * to your db object. * */ public static function restrictView($db, $module = null, $check_dates = true, $source_table = null) { $now = time(); if (empty($source_table)) { $source_table = $db->tables[0]; } if ($source_table == 'phpws_key') { if (!isset($db->tables[1])) { return PHPWS_Error::get(KEY_RESTRICT_NO_TABLE, 'core', 'Key::restrictView'); } $source_table = $db->tables[1]; $key_table = true; } else { $key_table = false; } if (!$key_table) { $db->addJoin('left', $source_table, 'phpws_key', 'key_id', 'id'); } else { $db->addJoin('left', 'phpws_key', $source_table, 'id', 'key_id'); } $db->addWhere("{$source_table}.key_id", '0', null, null, 'base'); $db->addWhere('phpws_key.active', 1, null, null, 'active'); $db->groupIn('active', 'base'); $db->setGroupConj('active', 'or'); if (Current_User::isDeity() || isset($module) && Current_User::isUnrestricted($module)) { return; } if ($check_dates) { $db->addWhere('phpws_key.show_after', $now, '<', null, 'active'); $db->addWhere('phpws_key.hide_after', $now, '>', null, 'active'); } if (!Current_User::isLogged()) { $db->addWhere('phpws_key.restricted', 0, null, 'and', 'active'); return; } else { $groups = Current_User::getGroups(); if (empty($groups)) { return; } $db->addJoin('left', 'phpws_key', 'phpws_key_view', 'id', 'key_id'); // if key only has a level 1 restriction, a logged user can view it $db->addWhere('phpws_key.restricted', KEY_LOGGED_RESTRICTED, '<=', null, 'restrict_1'); $db->setGroupConj('restrict_1', 'and'); // at level 2, the user must be in a group given view permissions $db->addWhere('phpws_key.restricted', KEY_GROUP_RESTRICTED, '=', null, 'restrict_2'); $db->addWhere('phpws_key_view.group_id', $groups, 'in', null, 'restrict_2'); $db->setGroupConj('restrict_2', 'or'); if (empty($module)) { $levels = Current_User::getUnrestrictedLevels(); if (!empty($levels)) { $db->addWhere('phpws_key.module', $levels, null, null, 'permission'); $db->groupIn('permission', 'restrict_2'); } } $db->groupIn('restrict_1', 'base'); $db->groupIn('restrict_2', 'restrict_1'); } }
/** * Returns the content of the the pager object */ public function get($return_blank_results = true) { $template = array(); if (empty($this->display_rows)) { $result = $this->initialize(); if (PHPWS_Error::isError($result)) { return $result; } } // Report ends the function call if ($this->report_type && $this->report_row) { $this->createReport(); exit; } if (!isset($this->module)) { return PHPWS_Error::get(DBPAGER_MODULE_NOT_SET, 'core', 'DBPager::get'); } if (!isset($this->template)) { return PHPWS_Error::get(DBPAGER_TEMPLATE_NOT_SET, 'core', 'DBPager::get'); } $rows = $this->getPageRows(); if (PHPWS_Error::isError($rows)) { return $rows; } if (isset($this->toggles)) { $max_tog = count($this->toggles); } $count = 0; $this->getNavigation($template); $this->getSortButtons($template); if (isset($rows)) { foreach ($rows as $rowitem) { if (isset($max_tog)) { if ($max_tog == 1) { if ($count % 2) { $rowitem['TOGGLE'] = $this->toggles[0]; } else { $rowitem['TOGGLE'] = null; } $count++; } else { $rowitem['TOGGLE'] = $this->toggles[$count]; $count++; if ($count >= $max_tog) { $count = 0; } } } else { $rowitem['TOGGLE'] = null; } $template['listrows'][] = $rowitem; } } elseif (!$return_blank_results) { return null; } else { $template['EMPTY_MESSAGE'] = $this->empty_message; } DBPager::plugPageTags($template); $this->final_template =& $template; return PHPWS_Template::process($template, $this->module, $this->template); }
/** * Moves a box to a new location */ public function move($dest) { if ($dest != 'move_box_up' && $dest != 'move_box_down' && $dest != 'move_box_top' && $dest != 'move_box_bottom' && $dest != 'restore') { $themeVars = $_SESSION['Layout_Settings']->getAllowedVariables(); if (!in_array($dest, $themeVars)) { return PHPWS_Error::get(LAYOUT_BAD_THEME_VAR, 'layout', 'Layout_Box::move', $dest); } $themeVar = $this->theme_var; $this->setThemeVar($dest); $this->setBoxOrder(NULL); $this->save(); $this->reorderBoxes($this->theme, $themeVar); return; } $db = new PHPWS_DB('layout_box'); $db->addWhere('id', $this->id, '!='); $db->addWhere('theme', $this->theme); $db->addWhere('theme_var', $this->theme_var); $db->addOrder('box_order'); $db->setIndexBy('box_order'); $boxes = $db->getObjects('Layout_Box'); if (empty($boxes)) { return NULL; } if (PHPWS_Error::isError($boxes)) { PHPWS_Error::log($boxes); return NULL; } switch ($dest) { case 'restore': $this->kill(); $this->reorderBoxes($this->theme, $this->theme_var); Layout::resetBoxes(); return; break; case 'move_box_up': if ($this->box_order == 1) { $this->move('move_box_bottom'); return; } else { $old_box =& $boxes[$this->box_order - 1]; $old_box->box_order++; $this->box_order--; if (!PHPWS_Error::logIfError($old_box->save())) { PHPWS_Error::logIfError($this->save()); } return; } break; case 'move_box_down': if ($this->box_order == count($boxes) + 1) { $this->move('move_box_top'); return; } else { $old_box =& $boxes[$this->box_order + 1]; $old_box->box_order--; $this->box_order++; if (!PHPWS_Error::logIfError($old_box->save())) { PHPWS_Error::logIfError($this->save()); } return; } break; case 'move_box_top': $this->box_order = 1; $this->save(); $count = 2; break; case 'move_box_bottom': $this->box_order = count($boxes) + 1; $this->save(); $count = 1; break; } foreach ($boxes as $box) { $box->box_order = $count; $box->save(); $count++; } }
public function init($file = true) { $title =& $this->title; if ($title == 'core') { $this->setDirectory(PHPWS_SOURCE_DIR . 'core/'); // even if use_file is false, we get the version_http from the file $filename = PHPWS_SOURCE_DIR . 'core/boost/boost.php'; if (!is_file($filename)) { $this->_error = PHPWS_Error::get(PHPWS_FILE_NOT_FOUND, 'core', 'PHPWS_Module::init', $filename); } else { include $filename; } if (!$file) { $db = new PHPWS_DB('core_version'); $db->addColumn('version'); $version = $db->select('one'); } $this->_dependency = (bool) $dependency; $this->setVersion($version); $this->setRegister(false); $this->setImportSQL(true); $this->setProperName('Core'); $this->setVersionHttp($version_http); $this->setAbout(true); } else { $this->setDirectory(PHPWS_SOURCE_DIR . "mod/{$title}/"); if ($file == true) { $result = PHPWS_Module::initByFile(); } else { $result = PHPWS_Module::initByDB(); } if (PHPWS_Error::isError($result)) { $this->_error = $result; } elseif (empty($result)) { $this->_error = PHPWS_Error::get(PHPWS_NO_MOD_FOUND, 'core', 'PHPWS_Module::init', $title); } } }
public function save($write = true, $thumbnail = true) { if (empty($this->file_directory)) { if ($this->folder_id) { $folder = new Folder($_POST['folder_id']); if ($folder->id) { $this->setDirectory($folder->getFullDirectory()); } else { return PHPWS_Error::get(FC_MISSING_FOLDER, 'filecabinet', 'PHPWS_Multimedia::save'); } } else { return PHPWS_Error::get(FC_DIRECTORY_NOT_SET, 'filecabinet', 'PHPWS_Multimedia::save'); } } if ($write) { $result = $this->write(); if (PHPWS_Error::isError($result)) { return $result; } } if (!$this->width || !$this->height) { $this->loadDimensions(); } if ($thumbnail) { if ($this->isVideo()) { $this->makeVideoThumbnail(); } else { $this->makeAudioThumbnail(); } } if (empty($this->title)) { $this->title = $this->file_name; } $db = new PHPWS_DB('multimedia'); $result = $db->saveObject($this); return $result; }
/** * Loads the settings into the session * */ public static function load($module) { $default = PHPWS_Settings::loadConfig($module); if (!$default) { $GLOBALS['PHPWS_Settings'][$module] = 1; return PHPWS_Error::get(SETTINGS_MISSING_FILE, 'core', 'PHPWS_Settings::load', $module); } include $default; PHPWS_Settings::set($module, $settings); $db = new PHPWS_DB('mod_settings'); $db->addWhere('module', $module); $result = $db->select(); if (PHPWS_Error::isError($result)) { return $result; } elseif (empty($result)) { PHPWS_Settings::save($module); } else { foreach ($result as $key => $value) { switch ($value['setting_type']) { case 1: $setval = $value['small_num']; break; case 2: $setval = $value['large_num']; break; case 3: $setval = $value['small_char']; break; case 4: $setval = $value['large_char']; break; } PHPWS_Settings::set($module, $value['setting_name'], $setval); } } return true; }
/** * Save this PHAT_Textarea * * @return mixed Message on success and PHPWS_Error on failure * @access public */ function save() { $error = FALSE; $result = $this->setValue($_REQUEST['PHAT_ElementValue']); if (PHPWS_Error::isError($result)) { $currentError = $result; $error = TRUE; } $label = $this->getLabel(); if (!$_SESSION['PHAT_FormManager']->form->checkLabel($_REQUEST['PHAT_ElementName']) && strcasecmp($label, $_REQUEST['PHAT_ElementName']) != 0 || PHPWS_Error::isError($this->setLabel(PHPWS_DB::sqlFriendlyName($_REQUEST['PHAT_ElementName'])))) { $currentError = PHPWS_Error::get(PHATFORM_INVALID_NAME, 'phatform', 'PHAT_Textarea::save()'); $error = TRUE; } $result = $this->setBlurb($_REQUEST['PHAT_ElementBlurb']); if (PHPWS_Error::isError($result)) { $currentError = $result; $error = TRUE; } if (isset($_REQUEST['PHAT_ElementRequired'])) { $this->setRequired(TRUE); } else { $this->setRequired(FALSE); } $rows = PHPWS_Text::parseInput($_REQUEST['PHAT_ElementRows']); if ($rows) { $this->_rows = $rows; } else { $this->_rows = PHAT_DEFAULT_ROWS; } $cols = PHPWS_Text::parseInput($_REQUEST['PHAT_ElementCols']); if ($cols) { $this->_cols = $cols; } else { $this->_cols = PHAT_DEFAULT_COLS; } if ($error) { return $currentError; } else { if (PHPWS_Error::isError($this->commit())) { return PHPWS_Error::get(PHATFORM_ELEMENT_FAIL, 'phatform', 'PHAT_Textarea::save()', array(dgettext('phatform', 'Textarea'))); } else { return sprintf(dgettext('phatform', 'The %s element was saved successfully.'), dgettext('phatform', 'Textarea')); } } }
public function prewriteRotate() { $degrees = $this->_getDegrees(); if (!$degrees) { return true; } $tmp_file = $this->_upload->upload['tmp_name']; $cpy_file = $tmp_file . '.rs'; $result = PHPWS_File::rotateImage($tmp_file, $cpy_file, $degrees); if (!PHPWS_Error::logIfError($result) && !$result) { return PHPWS_Error::get(FC_IMAGE_DIMENSION, 'filecabinet', 'PHPWS_Image::prewriteRotate', array($this->width, $this->height, $this->_max_width, $this->_max_height)); } else { if (!@copy($cpy_file, $tmp_file)) { return PHPWS_Error::get(FC_IMAGE_DIMENSION, 'filecabinet', 'PHPWS_Image::prewriteRotate', array($this->width, $this->height, $this->_max_width, $this->_max_height)); } else { list($this->width, $this->height, $image_type, $image_attr) = getimagesize($tmp_file); return true; } } return true; }
/** * Plugs an array of $variables into the $object. The associative array * keys must be identical to the object's variable names. * * 5/17/06 Removed the code that prevent private variables from loading. * Added 10/15/2008: * If arguments are sent in the third parameter, plugObject will call * the object's postPlug function and send those arguments to it. */ public static function plugObject($object, $variables, $args = null) { $post_plug = isset($args) && method_exists($object, 'postPlug'); $className = get_class($object); $classVars = get_class_vars($className); if (!is_array($classVars) || empty($classVars)) { return PHPWS_Error::get(PHPWS_CLASS_VARS, 'core', 'PHPWS_Core::plugObject', $className); } if (isset($variables) && !is_array($variables)) { return PHPWS_Error::get(PHPWS_WRONG_TYPE, 'core', __CLASS__ . '::' . __FUNCTION__, gettype($variables)); } foreach ($classVars as $key => $value) { if (isset($variables[$key])) { if (preg_match('/^[aO]:\\d+:/', $variables[$key])) { $object->{$key} = unserialize($variables[$key]); } else { $object->{$key} = $variables[$key]; } } } if ($post_plug) { $object->postPlug($args); } return true; }
/** * Copies a file from one directory to another * * This function comes from php.net by jacob@keystreams.com. * * Example Usage: * $copy = fileCopy('/path/to/original.file', '/path/to/', 'destination.file', 1, 1); * * @author jacob@NOSPAM.keystreams.com <*****@*****.**> * @modified Adam Morton <*****@*****.**> * @param string $file_origin Path to file to be copied * @param string $destination_directory Directory to copy to * @param string $file_destination Name to be given to copied file * @param boolean $overwrite If true overwrite any file in the destination directory * @param boolean $fatal If true echo an error if the file does not exist. * @return boolean true on success, false on failure * @access public */ public static function fileCopy($file_origin, $destination_directory, $file_destination, $overwrite, $fatal) { if ($fatal) { $fp = fopen($file_origin, 'rb'); if (!$fp) { return PHPWS_Error::get(PHPWS_FILE_CANT_READ, 'core', 'PHPWS_File::fileCopy', $file_origin); } $dir_check = is_writable($destination_directory); if (!$dir_check) { return PHPWS_Error::get(PHPWS_DIR_NOT_WRITABLE, 'core', 'PHPWS_File::fileCopy', $destination_directory); } $dest_file_exists = file_exists($destination_directory . $file_destination); if ($dest_file_exists) { if ($overwrite) { $fp = is_writable($destination_directory . $file_destination); if (!$fp) { return PHPWS_Error::get(PHPWS_DIR_NOT_WRITABLE, 'core', 'PHPWS_File::fileCopy', $destination_directory); } if ($copy_file = copy($file_origin, $destination_directory . $file_destination)) { return true; } else { return false; } } } else { if ($copy_file = copy($file_origin, $destination_directory . $file_destination)) { return true; } else { return false; } } } else { if ($copy_file = copy($file_origin, $destination_directory . $file_destination)) { return true; } else { return false; } } }
public function setType($type) { if ($this->isType($type)) { $this->type = $type; } else { return PHPWS_Error::get(EDITOR_MISSING_FILE, 'core', 'Editor::constructor', $type); } }
/** * Sets the page limit for this form to the provided $limit * * @param integer $limit The munber to set the page limit to. * @access public */ function setPageLimit($limit = PHAT_PAGE_LIMIT) { if (is_numeric($limit) && $limit > 0) { $this->_pageLimit = $limit; return TRUE; } else { return PHPWS_Error::get(PHATFORM_ELEMENT_NOT_OBJ, 'phatform', 'PHAT_Form::setPageLimit'); } }
/** * @version $Id$ * @author Adam Morton * @author Steven Levin */ function export($formId = NULL) { if (!isset($formId)) { $message = dgettext('phatform', 'No form ID was passed'); return new PHPWS_Error('phatform', 'export()', $message, 'continue', PHAT_DEBUG_MODE); } $exportDir = PHPWS_HOME_DIR . 'files/phatform/export/'; $path = $exportDir; clearstatcache(); if (!is_dir($path)) { if (is_writeable($exportDir)) { PHPWS_File::makeDir($path); } else { return PHPWS_Error::get(PHATFORM_EXPORT_PATH, 'phatform', 'Export.php::export()'); } } elseif (!is_writeable($path)) { return PHPWS_Error::get(PHATFORM_EXPORT_PATH, 'phatform', 'Export.php::export()'); } $sql = 'SELECT * FROM mod_phatform_form_' . $formId; $result = PHPWS_DB::getAll($sql); if (sizeof($result) > 0) { $data = ''; foreach ($result[0] as $key => $value) { if ($key != 'position') { $data .= $key . "\t"; } } foreach ($result as $entry) { $data .= "\n"; foreach ($entry as $key => $value) { if ($key != 'position') { if ($key == 'updated') { $value = date(PHPWS_DATE_FORMAT . ' ' . PHPWS_TIME_FORMAT, $value); } else { $value = str_replace("\t", " ", $value); $value = str_replace("\r\n", '', $value); $value = str_replace("\n", '', $value); $temp = $value; if (is_array($temp)) { $value = implode(',', $temp); } else { if (preg_match('/^[ao]:\\d+:/', $temp)) { // unserialize data $unsTemp = unserialize($temp); if (is_array($unsTemp)) { $value = implode(',', $unsTemp); } else { $value = $unsTemp; } } } } $data .= "{$value}\t"; } } } } $filename = 'form_' . $formId . '_export.' . time() . '.csv'; $file = fopen($path . $filename, 'w'); fwrite($file, $data); fclose($file); $goCode = 'zip -qmj ' . $path . $filename . '.zip ' . $path . $filename; system($goCode); $filename = $filename . '.zip'; $filepath = 'files/phatform/export/' . $filename; header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filepath)) . ' GMT'); header('Cache-Control: private', false); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($filepath)); header('Connection: close'); readfile($filepath); exit; }
/** * Pulls variables from the object results. Calls object's formatting function if * specified. */ public function getPageRows() { $template = null; $count = 0; if (!isset($this->display_rows)) { return null; } foreach ($this->display_rows as $disp_row) { if (!empty($this->convert_date)) { foreach ($this->convert_date as $key => $format) { if ($this->class && isset($disp_row->{$key})) { $disp_row->{$key} = strftime($format, $disp_row->{$key}); } elseif (isset($disp_row[$key])) { $disp_row[$key] = strftime($format, $disp_row[$key]); } } } if (isset($this->class) && isset($this->run_methods)) { foreach ($this->run_methods as $run_function) { call_user_func(array($disp_row, $run_function)); } } if (isset($this->class)) { foreach ($this->_class_vars as $varname) { $template[$count][strtoupper($varname)] = $disp_row->{$varname}; } if (!empty($this->row_tags)) { if (!in_array($this->row_tags['method'], $this->_methods)) { return PHPWS_Error::get(DBPAGER_NO_METHOD, 'core', 'DBPager::getPageRows', $this->class . ':' . $this->row_tags['method']); } if (empty($this->row_tags['variable'])) { $row_result = call_user_func(array($disp_row, $this->row_tags['method'])); } else { $row_result = call_user_func_array(array($disp_row, $this->row_tags['method']), $this->row_tags['variable']); } if (!empty($row_result) && is_array($row_result)) { $template[$count] = array_merge($template[$count], $row_result); } } } else { foreach ($disp_row as $key => $value) { $template[$count][strtoupper($key)] = $value; } if (isset($this->run_function)) { $row_result = call_user_func($this->run_function, $disp_row); if (!empty($row_result) && is_array($row_result)) { $template[$count] = array_merge($template[$count], $row_result); } } } if (isset($this->toggle_function)) { if (!($count % $this->toggle_func_number)) { $row_result = call_user_func($this->toggle_function, $disp_row); if (!empty($row_result)) { $template[$count] = array_merge($template[$count], $row_result); } } } $count++; } return $template; }
public function importSQL($file) { require_once 'File.php'; if (!is_file($file)) { return PHPWS_Error::get(BOOST_ERR_NO_INSTALLSQL, 'boost', 'importSQL', 'File: ' . $file); } $sql = File::readAll($file); $db = new PHPWS_DB(); $result = $db->import($sql); return $result; }
/** * Loads information sent to add function */ public static function getBoxContent() { $list = NULL; if (!isset($GLOBALS['Layout'])) { return PHPWS_Error::get(LAYOUT_SESSION_NOT_SET, 'layout', 'getBoxContent'); } foreach ($GLOBALS['Layout'] as $module => $content) { foreach ($content as $contentVar => $contentList) { if (empty($contentList) || !is_array($contentList)) { continue; } $list[$module][$contentVar] = implode('', $contentList); } } return $list; }
public function repeatWeekly(Calendar_Event $event) { if (!isset($_POST['weekday_repeat']) || !is_array($_POST['weekday_repeat'])) { $this->message = dgettext('calendar', 'You must choose which weekdays to repeat.'); return false; } $time_unit = $event->start_time + 86400; $copy_event = $event->repeatClone(); $time_diff = $event->end_time - $event->start_time; $max_count = 0; $repeat_days =& $_POST['weekday_repeat']; $dst_start = date('I', $event->start_time); while ($time_unit <= $event->end_repeat) { if (!in_array(strftime('%u', $time_unit), $repeat_days)) { $time_unit += 86400; continue; } $dst_current = date('I', $time_unit); if ($dst_current != $dst_start) { if ($dst_current) { $time_unit -= 3600; } else { $time_unit += 3600; } $dst_start = $dst_current; } $copy_event->id = 0; $max_count++; if ($max_count > CALENDAR_MAXIMUM_REPEATS) { return PHPWS_Error::get(CAL_REPEAT_LIMIT_PASSED, 'calendar', 'Calendar_Admin::repeatWeekly'); } $copy_event->start_time = $time_unit; $copy_event->end_time = $time_unit + $time_diff; $result = $copy_event->save(); if (PHPWS_Error::isError($result)) { return $result; } $time_unit += 86400; } return TRUE; }
public function saveObject($object, $stripChar = false, $autodetect_id = true) { if (!is_object($object)) { return PHPWS_Error::get(PHPWS_WRONG_TYPE, 'core', 'PHPWS_DB::saveObject', _('Type') . ': ' . gettype($object)); } $object_vars = get_object_vars($object); if (!is_array($object_vars)) { return PHPWS_Error::get(PHPWS_DB_NO_OBJ_VARS, 'core', 'PHPWS_DB::saveObject'); } foreach ($object_vars as $column => $value) { if ($stripChar == true) { $column = substr($column, 1); } $isTblColumn = $this->isTableColumn($column); if (PHPWS_Error::isError($isTblColumn)) { throw new Exception('Could not determine if column ' . $column . ' is a valid column in this table. Check table ownership.'); } if (!$isTblColumn) { continue; } if ($autodetect_id && ($column == 'id' && $value > 0)) { $this->addWhere('id', $value); } $this->addValue($column, $value); } if (isset($this->qwhere) || !empty($this->where)) { $result = $this->update(); } else { $result = $this->insert($autodetect_id); if (is_numeric($result)) { if (array_key_exists('id', $object_vars)) { $object->id = (int) $result; } elseif (array_key_exists('_id', $object_vars)) { $object->_id = (int) $result; } } } $this->resetValues(); return $result; }
/** * Remove this PHAT_Element * * @accesss public */ function remove() { if (isset($_REQUEST['PHAT_Yes'])) { $result = $this->kill(); if (PHPWS_Error::isError($result)) { return PHPWS_Error::get(PHATFORM_CANNOT_DELETE_ELEMENT, 'phatform', 'PHAT_Element::remove()'); } else { $result = $_SESSION['PHAT_FormManager']->form->popElement(); if (PHPWS_Error::isError($result)) { return $result; } else { return dgettext('phatform', 'The element was successfully removed.'); } } } else { if (isset($_REQUEST['PHAT_No'])) { return dgettext('phatform', 'No element was removed.'); } else { $className = get_class($this); $properName = ucfirst(str_ireplace('phat_', '', $className)); $tags['MESSAGE'] = sprintf(dgettext('phatform', 'Are you sure you want to remove this %s element?'), '<b><i>' . $properName . '</i></b>'); $tags['YES_BUTTON'] = PHPWS_Form::formSubmit('Yes', 'PHAT_Yes'); $tags['NO_BUTTON'] = PHPWS_Form::formSubmit('No', 'PHAT_No'); $tags['ELEMENT_PREVIEW'] = $this->view(); $elements[0] = PHPWS_Form::formHidden('module', 'phatform'); $elements[0] .= PHPWS_Form::formHidden('PHAT_EL_OP', 'RemoveElement'); $elements[0] .= PHPWS_Template::processTemplate($tags, 'phatform', 'form/deleteConfirm.tpl'); $content = PHPWS_Form::makeForm('PHAT_Confirm', 'index.php', $elements); } } return $content; }