/** * Layout Page Logic * @return * @param $db Object */ function __construct(database $db, user $user) { $this->db =& $db; $this->user =& $user; $this->sub_page = Kit::GetParam('sp', _GET, _WORD, 'view'); $this->layoutid = Kit::GetParam('layoutid', _REQUEST, _INT); // If we have modify selected then we need to get some info if ($this->layoutid != '') { // get the permissions Debug::LogEntry('audit', 'Loading permissions for layoutid ' . $this->layoutid); $this->auth = $user->LayoutAuth($this->layoutid, true); if (!$this->auth->edit) { trigger_error(__("You do not have permissions to edit this layout"), E_USER_ERROR); } $this->sub_page = "edit"; $sql = " SELECT layout, description, userid, retired, xml FROM layout "; $sql .= sprintf(" WHERE layoutID = %d ", $this->layoutid); if (!($results = $db->query($sql))) { trigger_error($db->error()); trigger_error(__("Cannot retrieve the Information relating to this layout. The layout may be corrupt."), E_USER_ERROR); } if ($db->num_rows($results) == 0) { $this->has_permissions = false; } while ($aRow = $db->get_row($results)) { $this->layout = Kit::ValidateParam($aRow[0], _STRING); $this->description = Kit::ValidateParam($aRow[1], _STRING); $this->retired = Kit::ValidateParam($aRow[3], _INT); $this->xml = $aRow[4]; } } }
protected function handle_form_data($file, $index) { // Handle form data, e.g. $_REQUEST['description'][$index] // Link the file to the module $name = $_REQUEST['name'][$index]; $duration = $_REQUEST['duration'][$index]; $layoutId = Kit::GetParam('layoutid', _REQUEST, _INT); $type = Kit::GetParam('type', _REQUEST, _WORD); Debug::LogEntry('audit', 'Upload complete for Type: ' . $type . ' and file name: ' . $file->name . '. Name: ' . $name . '. Duration:' . $duration); // We want to create a module for each of the uploaded files. // Do not pass in the region ID so that we only assign to the library and not to the layout try { $module = ModuleFactory::createForLibrary($type, $layoutId, $this->options['db'], $this->options['user']); } catch (Exception $e) { $file->error = $e->getMessage(); exit; } // We want to add this item to our library if (!($storedAs = $module->AddLibraryMedia($file->name, $name, $duration, $file->name))) { $file->error = $module->GetErrorMessage(); } // Set new file details $file->storedas = $storedAs; // Delete the file @unlink($this->get_upload_path($file->name)); }
function Grid() { $db =& $this->db; $response = new ResponseManager(); $type = Kit::GetParam('filter_type', _POST, _WORD); $fromDt = Kit::GetParam('filter_fromdt', _POST, _STRING); setSession('sessions', 'Filter', Kit::GetParam('XiboFilterPinned', _REQUEST, _CHECKBOX, 'off')); setSession('sessions', 'filter_type', $type); setSession('sessions', 'filter_fromdt', $fromDt); $SQL = "SELECT session.userID, user.UserName, IsExpired, LastPage, session.LastAccessed, RemoteAddr, UserAgent "; $SQL .= "FROM `session` LEFT OUTER JOIN user ON user.userID = session.userID "; $SQL .= "WHERE 1 = 1 "; if ($fromDt != '') { // From Date is the Calendar Formatted DateTime in ISO format $SQL .= sprintf(" AND session.LastAccessed < '%s' ", DateManager::getMidnightSystemDate(DateManager::getTimestampFromString($fromDt))); } if ($type == "active") { $SQL .= " AND IsExpired = 0 "; } if ($type == "expired") { $SQL .= " AND IsExpired = 1 "; } if ($type == "guest") { $SQL .= " AND session.userID IS NULL "; } // Load results into an array $log = $db->GetArray($SQL); Debug::LogEntry('audit', $SQL); if (!is_array($log)) { trigger_error($db->error()); trigger_error(__('Error getting the log'), E_USER_ERROR); } $cols = array(array('name' => 'lastaccessed', 'title' => __('Last Accessed')), array('name' => 'isexpired', 'title' => __('Active'), 'icons' => true), array('name' => 'username', 'title' => __('User Name')), array('name' => 'lastpage', 'title' => __('Last Page')), array('name' => 'ip', 'title' => __('IP Address')), array('name' => 'browser', 'title' => __('Browser'))); Theme::Set('table_cols', $cols); $rows = array(); foreach ($log as $row) { $row['userid'] = Kit::ValidateParam($row['userID'], _INT); $row['username'] = Kit::ValidateParam($row['UserName'], _STRING); $row['isexpired'] = Kit::ValidateParam($row['IsExpired'], _INT) == 1 ? 0 : 1; $row['lastpage'] = Kit::ValidateParam($row['LastPage'], _STRING); $row['lastaccessed'] = DateManager::getLocalDate(strtotime(Kit::ValidateParam($row['LastAccessed'], _STRING))); $row['ip'] = Kit::ValidateParam($row['RemoteAddr'], _STRING); $row['browser'] = Kit::ValidateParam($row['UserAgent'], _STRING); // Edit $row['buttons'][] = array('id' => 'sessions_button_logout', 'url' => 'index.php?p=sessions&q=ConfirmLogout&userid=' . $row['userid'], 'text' => __('Logout')); $rows[] = $row; } Theme::Set('table_rows', $rows); $response->SetGridResponse(Theme::RenderReturn('table_render')); $response->Respond(); }
/** * Sets the Error for this Data object * @return * @param $errNo Object * @param $errMessage Object */ protected function SetError($errNo, $errMessage = '') { $this->error = true; // Is an error No provided? if (!is_numeric($errNo)) { $errMessage = $errNo; $errNo = -1; } $this->errorNo = $errNo; $this->errorMessage = $errMessage; Debug::LogEntry('audit', sprintf('Data Class: Error Number [%d] Error Message [%s]', $errNo, $errMessage), 'Data Module', 'SetError'); // Return false so that we can use this method as the return call for parent methods return false; }
/** * Gets and Sets the Local * @return */ public static function InitLocale() { $localeDir = 'locale'; $default = Config::GetSetting('DEFAULT_LANGUAGE'); global $transEngine; global $stream; //Debug::LogEntry('audit', 'IN', 'TranslationEngine', 'InitLocal'); // Try to get the local firstly from _REQUEST (post then get) $lang = Kit::GetParam('lang', _REQUEST, _WORD, ''); // Build an array of supported languages $supportedLangs = scandir($localeDir); if ($lang != '') { // Set the language Debug::LogEntry('audit', 'Set the Language from REQUEST [' . $lang . ']', 'TranslationEngine', 'InitLocal'); // Is this language supported? // if not just use the default (eb_GB). if (!in_array($lang . '.mo', $supportedLangs)) { trigger_error(sprintf('Language not supported. %s', $lang)); // Use the default language instead. $lang = $default; } } else { $langs = Kit::GetParam('HTTP_ACCEPT_LANGUAGE', $_SERVER, _STRING); if ($langs != '') { //Debug::LogEntry('audit', ' HTTP_ACCEPT_LANGUAGE [' . $langs . ']', 'TranslationEngine', 'InitLocal'); $langs = explode(',', $langs); foreach ($langs as $lang) { // Remove any quality rating (as we aren't interested) $rawLang = explode(';', $lang); $lang = str_replace("-", "_", $rawLang[0]); if (in_array($lang . '.mo', $supportedLangs)) { //Debug::LogEntry('audit', 'Obtained the Language from HTTP_ACCEPT_LANGUAGE [' . $lang . ']', 'TranslationEngine', 'InitLocal'); break; } // Set lang as the default $lang = $default; } } else { $lang = $default; } } // We have the language //Debug::LogEntry('audit', 'Creating new file streamer for '. $localeDir . '/' . $lang . '.mo', 'TranslationEngine', 'InitLocal'); if (!($stream = new CachedFileReader($localeDir . '/' . $lang . '.mo'))) { trigger_error('Unable to translate this language'); $transEngine = false; return; } $transEngine = new gettext_reader($stream); }
public function Edit($setting, $value) { try { $dbh = PDOConnect::init(); $sth = $dbh->prepare('UPDATE setting SET value = :value WHERE setting = :setting'); $sth->execute(array('setting' => $setting, 'value' => $value)); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { $this->SetError(25000, __('Update of settings failed')); } return false; } }
public function Log($displayId, $type, $sizeInBytes) { try { $dbh = PDOConnect::init(); $sth = $dbh->prepare(' INSERT INTO `bandwidth` (Month, Type, DisplayID, Size) VALUES (:month, :type, :displayid, :size) ON DUPLICATE KEY UPDATE Size = Size + :size2 '); $sth->execute(array('month' => strtotime(date('m') . '/02/' . date('Y') . ' 00:00:00'), 'type' => $type, 'displayid' => $displayId, 'size' => $sizeInBytes, 'size2' => $sizeInBytes)); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); return false; } }
/** * Deletes a Category * @param <type> $categoryID * @return <type> */ public function Delete($categoryID) { try { $dbh = PDOConnect::init(); $sth = $dbh->prepare('DELETE FROM category WHERE categoryID = :categoryid'); $sth->execute(array('categoryid' => $categoryID)); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { $this->SetError(25000, __('Cannot delete this category.')); } return false; } }
/** * Unlink all media from the provided media item * @param int $mediaid The media item to unlink from */ public function UnlinkAllFromMedia($mediaid) { Debug::LogEntry('audit', 'IN', get_class(), __FUNCTION__); try { $dbh = PDOConnect::init(); $mediaid = Kit::ValidateParam($mediaid, _INT, false); $sth = $dbh->prepare('DELETE FROM `lkmediadisplaygroup` WHERE mediaid = :mediaid'); $sth->execute(array('mediaid' => $mediaid)); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__); if (!$this->IsError()) { $this->SetError(1, __('Unknown Error')); } return false; } }
public function Add($type, $fromDT, $toDT, $scheduleID, $displayID, $layoutID, $mediaID, $tag) { try { $dbh = PDOConnect::init(); // Lower case the type for consistancy $type = strtolower($type); // Prepare a statement $sth = $dbh->prepare('INSERT INTO stat (Type, statDate, start, end, scheduleID, displayID, layoutID, mediaID, Tag) VALUES (:type, :statdate, :start, :end, :scheduleid, :displayid, :layoutid, :mediaid, :tag)'); // Construct a parameters array to execute $params = array(); $params['statdate'] = date("Y-m-d H:i:s"); $params['type'] = $type; $params['start'] = $fromDT; $params['end'] = $toDT; $params['scheduleid'] = $scheduleID; $params['displayid'] = $displayID; $params['layoutid'] = $layoutID; // Optional parameters $params['mediaid'] = null; $params['tag'] = null; // We should run different SQL depending on what Type we are switch ($type) { case 'media': $params['mediaid'] = $mediaID; break; case 'layout': // Nothing additional to do break; case 'event': $params['layoutid'] = 0; $params['tag'] = $tag; break; default: // Nothing to do, just exit return true; } $sth->execute($params); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { $this->SetError(25000, 'Stat Insert Failed.'); } return false; } }
/** * Change a users password * @param <type> $userId * @param <type> $oldPassword * @param <type> $newPassword * @param <type> $retypedNewPassword * @return <type> */ public function ChangePassword($userId, $oldPassword, $newPassword, $retypedNewPassword, $forceChange = false) { try { $dbh = PDOConnect::init(); // Validate if ($userId == 0) { $this->ThrowError(26001, __('User not selected')); } // We can force the users password to change without having to provide the old one. // Is this a potential security hole - we must have validated that we are an admin to get to this point if (!$forceChange) { // Get the stored hash $sth = $dbh->prepare('SELECT UserPassword FROM `user` WHERE UserID = :userid'); $sth->execute(array('userid' => $userId)); if (!($row = $sth->fetch())) { $this->ThrowError(26000, __('Incorrect Password Provided')); } $good_hash = Kit::ValidateParam($row['UserPassword'], _STRING); // Check the Old Password is correct if ($this->validate_password($oldPassword, $good_hash) === false) { $this->ThrowError(26000, __('Incorrect Password Provided')); } } // Check the New Password and Retyped Password match if ($newPassword != $retypedNewPassword) { $this->ThrowError(26001, __('New Passwords do not match')); } // Check password complexity if (!$this->TestPasswordAgainstPolicy($newPassword)) { throw new Exception("Error Processing Request", 1); } // Generate a new SALT and Password $hash = $this->create_hash($newPassword); $sth = $dbh->prepare('UPDATE `user` SET UserPassword = :hash, CSPRNG = 1 WHERE UserID = :userid'); $sth->execute(array('hash' => $hash, 'userid' => $userId)); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { $this->SetError(25000, __('Could not edit Password')); } return false; } }
public function ErrorHandler($errno, $errmsg, $filename, $linenum, $vars) { // timestamp for the error entry $dt = date("Y-m-d H:i:s (T)"); // define an assoc array of error string // in reality the only entries we should // consider are E_WARNING, E_NOTICE, E_USER_ERROR, // E_USER_WARNING and E_USER_NOTICE $errortype = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice', E_RECOVERABLE_ERROR => 'Recoverable Error', 8192 => 'Deprecated Call'); // set of errors for which a var trace will be saved $user_errors_halt = array(E_USER_ERROR); $user_errors_inline = array(E_USER_WARNING); $err = "<errormsg>" . $errmsg . "</errormsg>\n"; $err .= "<errornum>" . $errno . "</errornum>\n"; $err .= "<errortype>" . $errortype[$errno] . "</errortype>\n"; $err .= "<scriptname>" . $filename . "</scriptname>\n"; $err .= "<scriptlinenum>" . $linenum . "</scriptlinenum>\n"; // Log everything Debug::LogEntry("error", $err); // Test to see if this is a HALT error or not (we do the same if we are in production or not!) if (in_array($errno, $user_errors_halt)) { // We have a halt error Debug::LogEntry('audit', 'Creating a Response Manager to deal with the HALT Error.'); $response = new ResponseManager(); $response->SetError($errmsg); $response->Respond(); } // Is Debug Enabled? (i.e. Development or Support) if (error_reporting() != 0) { if (in_array($errno, $user_errors_inline)) { // This is an inline error - therefore we really want to pop up a message box with this in it - so we know? // For now we treat this like a halt error? Or do we just try and output some javascript to pop up an error // surely the javascript idea wont work in ajax? // or prehaps we add this to the session errormessage so we see it at a later date? echo $errmsg; die; } } // Must return false return false; }
/** * Module constructor. * @return * @param $db Object */ function __construct(database $db, user $user) { $this->db =& $db; $this->user =& $user; $mod = Kit::GetParam('mod', _REQUEST, _WORD); // If we have the module - create an instance of the module class // This will only be true when we are displaying the Forms if ($mod != '') { require_once "modules/{$mod}.module.php"; // Try to get the layout, region and media id's $layoutid = Kit::GetParam('layoutid', _REQUEST, _INT); $regionid = Kit::GetParam('regionid', _REQUEST, _STRING); $mediaid = Kit::GetParam('mediaid', _REQUEST, _STRING); $lkid = Kit::GetParam('lkid', _REQUEST, _INT); Debug::LogEntry('audit', 'Creating new module with MediaID: ' . $mediaid . ' LayoutID: ' . $layoutid . ' and RegionID: ' . $regionid); if (!($this->module = new $mod($db, $user, $mediaid, $layoutid, $regionid, $lkid))) { trigger_error($this->module->GetErrorMessage(), E_USER_ERROR); } } return true; }
function __construct(database $db, user $user) { $this->db =& $db; $this->user =& $user; $this->layoutid = Kit::GetParam('layoutid', _REQUEST, _INT); //if we have modify selected then we need to get some info if ($this->layoutid != '') { // get the permissions Debug::LogEntry('audit', 'Loading permissions for layoutid ' . $this->layoutid); $layout = $this->user->LayoutList(NULL, array('layoutId' => $this->layoutid)); if (count($layout) <= 0) { trigger_error(__('You do not have permissions to view this layout'), E_USER_ERROR); } $layout = $layout[0]; $this->layout = $layout['layout']; $this->description = $layout['description']; $this->retired = $layout['retired']; $this->tags = $layout['tags']; $this->xml = $layout['xml']; } }
public function add($tag) { try { $dbh = PDOConnect::init(); // See if it exists $sth = $dbh->prepare('SELECT * FROM `tag` WHERE tag = :tag'); $sth->execute(array('tag' => $tag)); if ($row = $sth->fetch()) { return Kit::ValidateParam($row['tagId'], _INT); } // Insert if not $sth = $dbh->prepare('INSERT INTO `tag` (tag) VALUES (:tag)'); $sth->execute(array('tag' => $tag)); return $dbh->lastInsertId(); } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__); if (!$this->IsError()) { $this->SetError(1, __('Unknown Error')); } return false; } }
function login() { $db =& $this->db; $user =& $this->user; global $session; // this page must be called from a form therefore we expect POST variables $username = Kit::GetParam('username', _POST, _USERNAME); $password = Kit::GetParam('password', _POST, _PASSWORD); $referingpage = rawurldecode(Kit::GetParam('referingPage', _GET, _STRING)); // Check the token if (!Kit::CheckToken()) { // We would usually issue a HALT error here - but in the case of login we should redirect instead trigger_error('Token does not match'); // Split on & and rejoin with & $params = explode('&', $referingpage, 3); unset($params['message']); $referingpage = implode('&', $params) . '&message=Token Error'; header('Location:index.php?' . $referingpage); exit; } if ($user->login($username, $password)) { $userid = Kit::GetParam('userid', _SESSION, _INT); $username = Kit::GetParam('username', _SESSION, _USERNAME); setMessage($username . ' logged in'); $session->set_user(session_id(), $userid, 'user'); } Debug::LogEntry('audit', 'Login with refering page: ' . $referingpage); if ($referingpage == '') { header('Location:index.php?p=index'); } else { // Split on & and rejoin with & $params = explode('&', $referingpage, 3); unset($params['message']); $referingpage = implode('&', $params); header('Location:index.php?' . $referingpage); } exit; }
/** * Install or Update this module */ public function InstallOrUpdate() { // This function should update the `module` table with information about your module. // The current version of the module in the database can be obtained in $this->schemaVersion // The current version of this code can be obtained in $this->codeSchemaVersion // $settings will be made available to all instances of your module in $this->settings. These are global settings to your module, // not instance specific (i.e. not settings specific to the layout you are adding the module to). // $settings will be collected from the Administration -> Modules CMS page. // // Layout specific settings should be managed with $this->SetOption in your add / edit forms. Debug::LogEntry('audit', 'Request to install or update with schemaversion: ' . $this->schemaVersion, 'clock', 'InstallOrUpdate'); if ($this->schemaVersion <= 1) { // Install Debug::LogEntry('audit', 'Installing Clock module', 'clock', 'InstallOrUpdate'); $this->InstallModule('Clock', 'Display a Clock', 'forms/library.gif', 1, 1, array()); } else { // Update // No updates required to this module. // Call "$this->UpdateModule($name, $description, $imageUri, $previewEnabled, $assignable, $settings)" with the updated items } // Check we are all installed $this->InstallFiles(); }
/** * Displays the particular help subject / page * @return */ function Display() { $db =& $this->db; $user =& $this->user; $response = new ResponseManager(); $width = 1000; $height = 650; $topic = Kit::GetParam('Topic', _REQUEST, _WORD); $category = Kit::GetParam('Category', _REQUEST, _WORD, 'General'); if ($topic != '') { Debug::LogEntry('audit', 'Help requested for Topic = ' . $topic); // Look up this help topic / category in the db $SQL = "SELECT Link FROM help WHERE Topic = '%s' and Category = '%s'"; $SQL = sprintf($SQL, $db->escape_string($topic), $db->escape_string($category)); Debug::LogEntry('audit', $SQL); if (!($results = $db->query($SQL))) { trigger_error($db->error()); trigger_error(__('Error getting Help Link'), E_USER_ERROR); } if ($db->num_rows($results) != 0) { $row = $db->get_row($results); $link = $row[0]; // Store the link for the requested help page $this->helpLink = $link; } else { trigger_error(sprintf(__('No help file found for Topic %s and Category %s.'), $topic, $category), E_USER_ERROR); } } else { trigger_error(__('You must specify a help page.'), E_USER_ERROR); } $helpLink = $this->helpLink; $out = '<iframe class="full-iframe" src="' . $helpLink . '"></iframe>'; $response->SetFormRequestResponse($out, __('Help'), $width, $height); $response->Respond(); return true; }
/** * Displays the Library Assign form * @return */ function LayoutAssignForm() { $db =& $this->db; $user =& $this->user; $response = new ResponseManager(); // Input vars $campaignId = Kit::GetParam('CampaignID', _GET, _INT); $id = uniqid(); Theme::Set('id', $id); Theme::Set('form_meta', '<input type="hidden" name="p" value="campaign"><input type="hidden" name="q" value="LayoutAssignView">'); Theme::Set('pager', ResponseManager::Pager($id, 'grid_pager')); // Get the currently assigned layouts and put them in the "well" $layoutsAssigned = Layout::Entries(array('lkcl.DisplayOrder'), array('campaignId' => $campaignId)); if (!is_array($layoutsAssigned)) { trigger_error($db->error()); trigger_error(__('Error getting Layouts'), E_USER_ERROR); } Debug::LogEntry('audit', count($layoutsAssigned) . ' layouts assigned already'); $formFields = array(); $formFields[] = FormManager::AddText('filter_name', __('Name'), NULL, NULL, 'l'); $formFields[] = FormManager::AddText('filter_tags', __('Tags'), NULL, NULL, 't'); Theme::Set('form_fields', $formFields); // Set the layouts assigned Theme::Set('layouts_assigned', $layoutsAssigned); Theme::Set('append', Theme::RenderReturn('campaign_form_layout_assign')); // Call to render the template Theme::Set('header_text', __('Choose Layouts')); $output = Theme::RenderReturn('grid_render'); // Construct the Response $response->html = $output; $response->success = true; $response->dialogSize = true; $response->dialogWidth = '780px'; $response->dialogHeight = '580px'; $response->dialogTitle = __('Layouts on Campaign'); $response->AddButton(__('Help'), 'XiboHelpRender("' . HelpManager::Link('Campaign', 'Layouts') . '")'); $response->AddButton(__('Cancel'), 'XiboDialogClose()'); $response->AddButton(__('Save'), 'LayoutsSubmit("' . $campaignId . '")'); $response->Respond(); }
private function GetDataSetItems($displayId, $text) { $db =& $this->db; // Extra fields for data sets $dataSetId = $this->GetOption('datasetid'); $upperLimit = $this->GetOption('upperLimit'); $lowerLimit = $this->GetOption('lowerLimit'); $filter = $this->GetOption('filter'); $ordering = $this->GetOption('ordering'); Debug::LogEntry('audit', 'Then template for each row is: ' . $text); // Combine the column id's with the dataset data $matches = ''; preg_match_all('/\\[(.*?)\\]/', $text, $matches); $columnIds = array(); foreach ($matches[1] as $match) { // Get the column id's we are interested in Debug::LogEntry('audit', 'Matched column: ' . $match); $col = explode('|', $match); $columnIds[] = $col[1]; } // Get the dataset results Kit::ClassLoader('dataset'); $dataSet = new DataSet($db); $dataSetResults = $dataSet->DataSetResults($dataSetId, implode(',', $columnIds), $filter, $ordering, $lowerLimit, $upperLimit, $displayId, true); $items = array(); foreach ($dataSetResults['Rows'] as $row) { // For each row, substitute into our template $rowString = $text; foreach ($matches[1] as $sub) { // Pick the appropriate column out $subs = explode('|', $sub); $rowString = str_replace('[' . $sub . ']', $row[$subs[0]], $rowString); } $items[] = $rowString; } return $items; }
/** * Member of Display Groups Form */ public function MemberOfForm() { $db =& $this->db; $response = new ResponseManager(); $displayID = Kit::GetParam('DisplayID', _REQUEST, _INT); // Auth $auth = $this->user->DisplayGroupAuth($this->GetDisplayGroupId($displayID), true); if (!$auth->modifyPermissions) { trigger_error(__('You do not have permission to change Display Groups on this display'), E_USER_ERROR); } // There needs to be two lists here. // - DisplayGroups this Display is already assigned to // - DisplayGroups this Display could be assigned to // Set some information about the form Theme::Set('displaygroups_assigned_id', 'displaysIn'); Theme::Set('displaygroups_available_id', 'displaysOut'); Theme::Set('displaygroups_assigned_url', 'index.php?p=display&q=SetMemberOf&DisplayID=' . $displayID); // Display Groups Assigned $SQL = ""; $SQL .= "SELECT displaygroup.DisplayGroupID, "; $SQL .= " displaygroup.DisplayGroup, "; $SQL .= " CONCAT('DisplayGroupID_', displaygroup.DisplayGroupID) AS list_id "; $SQL .= "FROM displaygroup "; $SQL .= " INNER JOIN lkdisplaydg ON lkdisplaydg.DisplayGroupID = displaygroup.DisplayGroupID "; $SQL .= sprintf("WHERE lkdisplaydg.DisplayID = %d ", $displayID); $SQL .= " AND displaygroup.IsDisplaySpecific = 0 "; $SQL .= " ORDER BY displaygroup.DisplayGroup "; $displaygroupsAssigned = $db->GetArray($SQL); if (!is_array($displaygroupsAssigned)) { trigger_error($db->error()); trigger_error(__('Error getting Display Groups'), E_USER_ERROR); } Theme::Set('displaygroups_assigned', $displaygroupsAssigned); // Display Groups not assigned $SQL = ""; $SQL .= "SELECT displaygroup.DisplayGroupID, "; $SQL .= " displaygroup.DisplayGroup, "; $SQL .= " CONCAT('DisplayGroupID_', displaygroup.DisplayGroupID) AS list_id "; $SQL .= " FROM displaygroup "; $SQL .= " WHERE displaygroup.IsDisplaySpecific = 0 "; $SQL .= " AND displaygroup.DisplayGroupID NOT IN "; $SQL .= " (SELECT lkdisplaydg.DisplayGroupID "; $SQL .= " FROM lkdisplaydg "; $SQL .= sprintf(" WHERE lkdisplaydg.DisplayID = %d ", $displayID); $SQL .= " )"; $SQL .= " ORDER BY displaygroup.DisplayGroup "; Debug::LogEntry('audit', $SQL); $displaygroups_available = $db->GetArray($SQL); if (!is_array($displaygroups_available)) { trigger_error($db->error()); trigger_error(__('Error getting Display Groups'), E_USER_ERROR); } Theme::Set('displaygroups_available', $displaygroups_available); // Render the theme $form = Theme::RenderReturn('display_form_group_assign'); $response->SetFormRequestResponse($form, __('Manage Membership'), '400', '375', 'DisplayGroupManageMembersCallBack'); $response->AddButton(__('Help'), 'XiboHelpRender("' . HelpManager::Link('DisplayGroup', 'Members') . '")'); $response->AddButton(__('Cancel'), 'XiboDialogClose()'); $response->AddButton(__('Save'), 'DisplayGroupMembersSubmit()'); $response->Respond(); }
public function displayUp($displayId) { try { $dbh = PDOConnect::init(); Debug::Audit('Display Up: ' . $displayId); $sth = $dbh->prepare('UPDATE `stat` SET end = :toDt WHERE displayId = :displayId AND end IS NULL AND type = :type'); $sth->execute(array('toDt' => date('Y-m-d H:i:s'), 'type' => 'displaydown', 'displayId' => $displayId)); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__); if (!$this->IsError()) { $this->SetError(1, __('Unknown Error')); } return false; } }
/** * Checks a form token * @param string token * @return */ function CheckFormToken($token, $tokenName = "token") { global $db; if ($token == $_SESSION[$tokenName]) { // See if its still in Date if ($_SESSION[$tokenName . '_timeout'] + 1200 <= time()) { return false; } return true; } else { unset($_SESSION[$tokenName]); Debug::LogEntry('error', "Form token incorrect from: " . $_SERVER['REMOTE_ADDR'] . " with token [{$token}] for session_id [" . session_id() . ']'); return false; } }
/** * Updates the settings on the module * @param [array] $settings [The Settings] */ public function UpdateModuleSettings($settings) { if (!is_array($settings)) { return $this->SetError(__('Module settings must be an array')); } // Update the settings on the module record. try { $dbh = PDOConnect::init(); $sth = $dbh->prepare('UPDATE `module` SET settings = :settings WHERE ModuleID = :module_id'); $sth->execute(array('settings' => json_encode($settings), 'module_id' => $this->module_id)); } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); if (!$this->IsError()) { $this->SetError(1, __('Unknown Error')); } return false; } }
public function DeleteAll($dataSetId) { try { $dbh = PDOConnect::init(); $sth = $dbh->prepare('DELETE FROM datasetcolumn WHERE DataSetId = :datasetid'); $sth->execute(array('datasetid' => $dataSetId)); Debug::LogEntry('audit', 'Complete', 'DataSetColumn', 'DeleteAll'); return true; } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage()); return $this->SetError(25005, __('Could not delete DataSet Column')); } }
/** * Returns the Xibo Server version information * @return <type> */ public function Version() { $version = Config::Version(); Debug::LogEntry('audit', 'Called Version'); $xmlDoc = new DOMDocument(); $xmlElement = $xmlDoc->createElement('version'); foreach ($version as $key => $value) { $xmlElement->setAttribute($key, $value); } return $this->Respond($xmlElement); }
$user = new User($db); // Log this user in. if (!$user->LoginServices($userID)) { $serviceResponse->ErrorServerError('Unknown User.'); } } else { $serviceResponse->ErrorServerError('No user id.'); } } catch (OAuthException $e) { $serviceResponse->ErrorServerError('Request signed but Unauthorized.'); } } else { // Only signed requests allowed. $serviceResponse->ErrorServerError('Not signed.'); } Debug::LogEntry('audit', 'Authenticated API call for [' . $method . '] with a [' . $response . '] response. Issued by UserId: ' . $user->userid, 'Services'); // Authenticated with OAuth. Kit::ClassLoader('Rest'); // Detect response type requested. switch ($response) { case 'json': Kit::ClassLoader('RestJson'); $rest = new RestJson($db, $user, $_REQUEST); break; case 'xml': Kit::ClassLoader('RestXml'); $rest = new RestXml($db, $user, $_REQUEST); break; default: $serviceResponse->ErrorServerError('Unknown response type'); }
/** * Get Resource */ public function GetResource($displayId = 0) { $proportional = Kit::GetParam('proportional', _GET, _BOOL, true); $thumb = Kit::GetParam('thumb', _GET, _BOOL, false); $dynamic = isset($_REQUEST['dynamic']); $file = $this->storedAs; $width = intval(Kit::GetParam('width', _REQUEST, _DOUBLE, 80)); $height = intval(Kit::GetParam('height', _REQUEST, _DOUBLE, 80)); // File upload directory.. get this from the settings object $library = Config::GetSetting("LIBRARY_LOCATION"); $fileName = $library . $file; Debug::Audit(sprintf('Image Request %dx%d %s. Thumb: %s', $width, $height, $fileName, $thumb)); // If we are a thumb request then output the cached thumbnail if ($thumb) { $fileName = $library . sprintf('tn_%dx%d_%s', $width, $height, $file); // If the thumbnail doesn't exist then create one if (!file_exists($fileName)) { Debug::LogEntry('audit', 'File doesnt exist, creating a thumbnail for ' . $fileName); if (!($info = getimagesize($library . $file))) { die($library . $file . ' is not an image'); } ResizeImage($library . $file, $fileName, $width, $height, $proportional, 'file'); } } // Get the info for this new temporary file if (!($info = getimagesize($fileName))) { $fileName = 'theme/default/img/forms/filenotfound.png'; $this->ReturnFile($fileName); exit; } if ($dynamic && !$thumb && $info[2]) { $width = intval(Kit::GetParam('width', _REQUEST, _DOUBLE, 80)); $height = intval(Kit::GetParam('height', _REQUEST, _DOUBLE, 80)); // dynamically create an image of the correct size - used for previews ResizeImage($fileName, '', $width, $height, $proportional, 'browser'); exit; } if (!file_exists($fileName)) { //not sure Debug::LogEntry('audit', "Cant find: {$uid}", 'module', 'GetResource'); $fileName = 'theme/default/img/forms/filenotfound.png'; } $this->ReturnFile($fileName); exit; }
/** * Authenticates the current user and returns an array of display groups this user is authenticated on * @return */ public function DisplayGroupList($isDisplaySpecific = 0, $name = '') { $db =& $this->db; $userid =& $this->userid; $SQL = "SELECT displaygroup.DisplayGroupID, displaygroup.DisplayGroup, displaygroup.IsDisplaySpecific, displaygroup.Description "; if ($isDisplaySpecific == 1) { $SQL .= " , lkdisplaydg.DisplayID "; } $SQL .= " FROM displaygroup "; // If we are only interested in displays, then return the display if ($isDisplaySpecific == 1) { $SQL .= " INNER JOIN lkdisplaydg "; $SQL .= " ON lkdisplaydg.DisplayGroupID = displaygroup.DisplayGroupID "; } $SQL .= " WHERE 1 = 1 "; if ($name != '') { // convert into a space delimited array $names = explode(' ', $name); foreach ($names as $searchName) { // Not like, or like? if (substr($searchName, 0, 1) == '-') { $SQL .= " AND (displaygroup.DisplayGroup NOT LIKE '%" . sprintf('%s', ltrim($db->escape_string($searchName), '-')) . "%') "; } else { $SQL .= " AND (displaygroup.DisplayGroup LIKE '%" . sprintf('%s', $db->escape_string($searchName)) . "%') "; } } } if ($isDisplaySpecific == 1) { $SQL .= " AND displaygroup.IsDisplaySpecific = 1 "; } $SQL .= " ORDER BY displaygroup.DisplayGroup "; Debug::LogEntry('audit', sprintf('Retreiving list of displaygroups for %s with SQL: %s', $this->userName, $SQL)); if (!($result = $this->db->query($SQL))) { trigger_error($this->db->error()); return false; } $displayGroups = array(); while ($row = $this->db->get_assoc_row($result)) { $displayGroupItem = array(); // Validate each param and add it to the array. $displayGroupItem['displaygroupid'] = Kit::ValidateParam($row['DisplayGroupID'], _INT); $displayGroupItem['displaygroup'] = Kit::ValidateParam($row['DisplayGroup'], _STRING); $displayGroupItem['description'] = Kit::ValidateParam($row['Description'], _STRING); $displayGroupItem['isdisplayspecific'] = Kit::ValidateParam($row['IsDisplaySpecific'], _STRING); $displayGroupItem['displayid'] = $isDisplaySpecific == 1 ? Kit::ValidateParam($row['DisplayID'], _INT) : 0; $auth = $this->DisplayGroupAuth($displayGroupItem['displaygroupid'], true); if ($auth->view) { $displayGroupItem['view'] = (int) $auth->view; $displayGroupItem['edit'] = (int) $auth->edit; $displayGroupItem['del'] = (int) $auth->del; $displayGroupItem['modifypermissions'] = (int) $auth->modifyPermissions; $displayGroups[] = $displayGroupItem; } } return $displayGroups; }
private function InstallFonts() { $media = new Media(); $fontTemplate = ' @font-face { font-family: \'[family]\'; src: url(\'[url]\'); } '; // Save a fonts.css file to the library for use as a module try { $dbh = PDOConnect::init(); $sth = $dbh->prepare('SELECT mediaID, name, storedAs FROM `media` WHERE type = :type AND IsEdited = 0 ORDER BY name'); $sth->execute(array('type' => 'font')); $fonts = $sth->fetchAll(); if (count($fonts) < 1) { return; } $css = ''; $localCss = ''; $ckeditorString = ''; foreach ($fonts as $font) { // Separate out the display name and the referenced name (referenced name cannot contain any odd characters or numbers) $displayName = $font['name']; $familyName = preg_replace('/\\s+/', ' ', preg_replace('/\\d+/u', '', $font['name'])); // Css for the client contains the actual stored as location of the font. $css .= str_replace('[url]', $font['storedAs'], str_replace('[family]', $displayName, $fontTemplate)); // Css for the local CMS contains the full download path to the font $relativeRoot = explode('://', Kit::GetXiboRoot()); $url = '//' . $relativeRoot[1] . '?p=module&mod=font&q=Exec&method=GetResource&download=1&downloadFromLibrary=1&mediaid=' . $font['mediaID']; $localCss .= str_replace('[url]', $url, str_replace('[family]', $familyName, $fontTemplate)); // CKEditor string $ckeditorString .= $displayName . '/' . $familyName . ';'; } file_put_contents('modules/preview/fonts.css', $css); // Install it (doesn't expire, is a system file, force update) $media->addModuleFile('modules/preview/fonts.css', 0, true, true); // Generate a fonts.css file for use locally (in the CMS) file_put_contents('modules/preview/fonts.css', $localCss); // Edit the CKEditor file $ckeditor = file_get_contents('theme/default/libraries/ckeditor/config.js'); $replace = "/*REPLACE*/ config.font_names = '" . $ckeditorString . "' + config.font_names; /*ENDREPLACE*/"; $ckeditor = preg_replace('/\\/\\*REPLACE\\*\\/.*?\\/\\*ENDREPLACE\\*\\//', $replace, $ckeditor); file_put_contents('theme/default/libraries/ckeditor/config.js', $ckeditor); } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__); if (!$this->IsError()) { $this->SetError(1, __('Unknown Error')); } return false; } }