Esempio n. 1
0
 public function Error($errorNo, $errorMessage = '')
 {
     header('Content-Type: text/xml; charset=utf8');
     Debug::LogEntry('audit', $errorMessage, 'RestXml', 'Error');
     // Roll back any open transactions if we are in an error state
     try {
         $dbh = PDOConnect::init();
         $dbh->rollBack();
     } catch (Exception $e) {
         Debug::LogEntry('audit', 'Unable to rollback');
     }
     // Output the error doc
     $xmlDoc = new DOMDocument('1.0');
     $xmlDoc->formatOutput = true;
     // Create the response node
     $rootNode = $xmlDoc->createElement('rsp');
     // Set the status to OK
     $rootNode->setAttribute('status', 'error');
     // Append the response node as the root
     $xmlDoc->appendChild($rootNode);
     // Create the error node
     $errorNode = $xmlDoc->createElement('error');
     $errorNode->setAttribute('code', $errorNo);
     $errorNode->setAttribute('message', $errorMessage);
     // Add the error node to the document
     $rootNode->appendChild($errorNode);
     // Log it
     Debug::LogEntry('audit', $xmlDoc->saveXML());
     // Return it as a string
     return $xmlDoc->saveXML();
 }
Esempio n. 2
0
 /**
  * Defines the Version and returns it
  * @return 
  * @param $object String [optional]
  */
 static function Version($object = '')
 {
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('SELECT app_ver, XlfVersion, XmdsVersion, DBVersion FROM version');
         $sth->execute();
         if (!($row = $sth->fetch())) {
             throw new Exception('No results returned');
         }
         $appVer = Kit::ValidateParam($row['app_ver'], _STRING);
         $xlfVer = Kit::ValidateParam($row['XlfVersion'], _INT);
         $xmdsVer = Kit::ValidateParam($row['XmdsVersion'], _INT);
         $dbVer = Kit::ValidateParam($row['DBVersion'], _INT);
         if (!defined('VERSION')) {
             define('VERSION', $appVer);
         }
         if (!defined('DBVERSION')) {
             define('DBVERSION', $dbVer);
         }
         if ($object != '') {
             return Kit::GetParam($object, $row, _STRING);
         }
         return $row;
     } catch (Exception $e) {
         trigger_error($e->getMessage());
         trigger_error(__('No Version information - please contact technical support'), E_USER_WARNING);
     }
 }
Esempio n. 3
0
 public static function init()
 {
     if (!self::$conn) {
         global $dbhost;
         global $dbuser;
         global $dbpass;
         global $dbname;
         // Open the connection and set the error mode
         self::$conn = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname . ';', $dbuser, $dbpass);
         self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         self::$conn->query("SET NAMES 'utf8'");
     }
     return self::$conn;
 }
Esempio n. 4
0
 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;
     }
 }
Esempio n. 5
0
 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;
     }
 }
Esempio n. 6
0
 /**
  * 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;
     }
 }
Esempio n. 7
0
 /**
  * Audit Log
  * @param string $entity
  * @param int $entityId
  * @param string $message
  * @param string|object|array $object
  */
 public static function audit($entity, $entityId, $message, $object)
 {
     \Debug::Audit(sprintf('Audit Trail message recorded for %s with id %d. Message: %s', $entity, $entityId, $message));
     if (self::$_auditLogStatement == null) {
         $dbh = \PDOConnect::newConnection();
         self::$_auditLogStatement = $dbh->prepare('
             INSERT INTO `auditlog` (logDate, userId, entity, message, entityId, objectAfter)
               VALUES (:logDate, :userId, :entity, :message, :entityId, :objectAfter)
         ');
     }
     // If we aren't a string then encode
     if (!is_string($object)) {
         $object = json_encode($object);
     }
     self::$_auditLogStatement->execute(array('logDate' => time(), 'userId' => \Kit::GetParam('userid', _SESSION, _INT, 0), 'entity' => $entity, 'message' => $message, 'entityId' => $entityId, 'objectAfter' => $object));
 }
 /**
  * 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;
     }
 }
Esempio n. 9
0
 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;
     }
 }
 /**
  * Unlinks a display group from a group
  * @return
  * @param $displayGroupID Object
  * @param $groupID Object
  */
 public function UnlinkAll($displayGroupId)
 {
     Debug::LogEntry('audit', 'IN', 'DataSetGroupSecurity', 'Unlink');
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('DELETE FROM lkdisplaygroupgroup WHERE DisplayGroupID = :displaygroupid');
         $sth->execute(array('displaygroupid' => $displayGroupId));
         Debug::LogEntry('audit', 'OUT', 'DataSetGroupSecurity', 'Unlink');
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25007, __('Could not Unlink All Display Groups from User Group'));
         }
         return false;
     }
 }
 /**
  * Unlinks a display group from a group
  * @return
  * @param $displayGroupID Object
  * @param $groupID Object
  */
 public function UnlinkAll($templateId)
 {
     Debug::LogEntry('audit', 'IN', 'TemplateGroupSecurity', 'UnlinkAll');
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('DELETE FROM lktemplategroup WHERE TemplateID = :templateid');
         $sth->execute(array('templateid' => $templateId));
         Debug::LogEntry('audit', 'OUT', 'TemplateGroupSecurity', 'UnlinkAll');
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25025, __('Could not Unlink Template from Groups'));
         }
         return false;
     }
 }
Esempio n. 12
0
 /**
  * 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;
     }
 }
Esempio n. 13
0
 /**
  * Outputs a help link
  * @return 
  * @param $topic Object[optional]
  * @param $category Object[optional]
  */
 public static function Link($topic = "", $category = "General")
 {
     // if topic is empty use the page name
     $topic = $topic == '' ? Kit::GetParam('p', _REQUEST, _WORD) : $topic;
     $topic = ucfirst($topic);
     // Get the link
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('SELECT Link FROM help WHERE Topic = :topic and Category = :cat');
         $sth->execute(array('topic' => $topic, 'cat' => $category));
         if (!($link = $sth->fetchColumn(0))) {
             $sth->execute(array('topic' => $topic, 'cat' => 'General'));
             $link = $sth->fetchColumn(0);
         }
         return Config::GetSetting('HELP_BASE') . $link;
     } catch (Exception $e) {
         return false;
     }
 }
Esempio n. 14
0
 public function Error($errorNo, $errorMessage = '')
 {
     header('Content-Type: text/json; charset=utf8');
     Debug::LogEntry('audit', $errorMessage, 'RestJson', 'Error');
     // Roll back any open transactions if we are in an error state
     try {
         $dbh = PDOConnect::init();
         $dbh->rollBack();
     } catch (Exception $e) {
         Debug::LogEntry('audit', 'Unable to rollback', 'RestJson', 'Error');
     }
     // Error
     $array = array('status' => 'error', 'error' => array('code' => $errorNo, 'message' => $errorMessage));
     $return = json_encode($array);
     // Log it
     Debug::LogEntry('audit', $return, 'RestJson', 'Error');
     // Return it as a string
     return $return;
 }
Esempio n. 15
0
 /**
  * Deletes a layout
  * @param <type> $layoutId
  * @return <type>
  */
 public function Delete($templateId)
 {
     try {
         $dbh = PDOConnect::init();
         // Remove any permissions
         Kit::ClassLoader('templategroupsecurity');
         $security = new TemplateGroupSecurity($this->db);
         $security->UnlinkAll($templateId);
         // Remove the Template
         $sth = $dbh->prepare('DELETE FROM template WHERE TemplateId = :templateid');
         $sth->execute(array('templateid' => $templateId));
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25105, __('Unable to delete template'));
         }
         return false;
     }
 }
Esempio n. 16
0
 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;
     }
 }
Esempio n. 17
0
 public function Error($errorNo, $errorMessage = '')
 {
     Debug::LogEntry('audit', $errorMessage, 'RestXml', 'Error');
     header('Content-Type: text/json; charset=utf8');
     // Roll back any open transactions if we are in an error state
     try {
         $dbh = PDOConnect::init();
         $dbh->rollBack();
     } catch (Exception $e) {
         Debug::LogEntry('audit', 'Unable to rollback');
     }
     // Output the error doc
     $xmlDoc = new DOMDocument('1.0');
     $xmlDoc->formatOutput = true;
     $response['rsp']['status'] = 'error';
     $response['rsp']['status']['error']['code'] = $errorNo;
     $response['rsp']['status']['error']['message'] = $errorMessage;
     $return = json_encode($response);
     // Log it
     Debug::LogEntry('audit', $return);
     // Return it as a string
     return $return;
 }
Esempio n. 18
0
 /**
  * Authenticates this user against the given module
  * or if none provided returns an array of optional modules
  * @return Array
  * @param [Optional] $module String
  */
 public function ModuleAuth($regionSpecific, $module = '', $assignable = -1)
 {
     $userid =& $this->userid;
     try {
         $dbh = PDOConnect::init();
         // Check that the module is enabled
         $params = array();
         $SQL = "SELECT * FROM module WHERE Enabled = 1 ";
         if ($regionSpecific != -1) {
             $SQL .= " AND RegionSpecific = :regionspecific ";
             $params['regionspecific'] = $regionSpecific;
         }
         if ($assignable != -1) {
             $SQL .= " AND assignable = :assignable ";
             $params['assignable'] = $assignable;
         }
         if ($module != '') {
             $SQL .= " AND Module = :module ";
             $params['module'] = $module;
         }
         $SQL .= "  ORDER BY Name ";
         $sth = $dbh->prepare($SQL);
         $sth->execute($params);
         $modules = $sth->fetchAll();
         if (count($modules) == 0) {
             return false;
         }
         // Return this array
         return $modules;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         return false;
     }
 }
Esempio n. 19
0
    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;
        }
    }
Esempio n. 20
0
 /**
  * Outputs an internal server error
  */
 public function ErrorServerError($message = 'Unknown Error')
 {
     header('HTTP/1.1 500 Internal Server Error');
     header('Content-Type: text/plain');
     // Roll back any open transactions if we are in an error state
     try {
         $dbh = PDOConnect::init();
         $dbh->rollBack();
     } catch (Exception $e) {
         Debug::LogEntry('audit', 'Unable to rollBack');
     }
     die($message);
 }
Esempio n. 21
0
 public function Step8()
 {
     PDOConnect::init();
     // Define the VERSION
     Config::Version();
     Theme::Set('form_action', 'index.php?q=login');
     Theme::Set('about_url', 'index.php?p=index&q=About');
     Theme::Set('source_url', Theme::SourceLink());
     // Message (either from the URL or the session)
     Theme::Set('login_message', sprintf(__("%s was successfully installed. Please log-in with the user details you chose earlier."), Theme::GetConfig('app_name')));
     Theme::Render('login_page');
     // Install files
     Media::installAllModuleFiles();
     // Delete install
     if (!unlink('install.php')) {
         throw new Exception(__("Unable to delete install.php. Please ensure the webserver has permission to unlink this file and retry"));
     }
     exit;
 }
Esempio n. 22
0
 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'));
     }
 }
Esempio n. 23
0
 public function Verify()
 {
     // Check the token
     if (!Kit::CheckToken()) {
         trigger_error(__('Sorry the form has expired. Please refresh.'), E_USER_ERROR);
     }
     $response = new ResponseManager();
     try {
         $dbh = PDOConnect::init();
         $dbh->exec('UPDATE `media` SET valid = 0 WHERE moduleSystemFile = 1');
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
     Media::installAllModuleFiles();
     $response->SetFormSubmitResponse(__('Verified'), false);
     $response->Respond();
 }
 /**
  * Copys all region security for a layout
  * @param <type> $layoutId
  * @param <type> $newLayoutId
  * @return <type>
  */
 public function CopyAll($layoutId, $newLayoutId)
 {
     Debug::LogEntry('audit', 'IN', 'LayoutRegionGroupSecurity', 'Copy');
     try {
         $dbh = PDOConnect::init();
         $SQL = "";
         $SQL .= "INSERT ";
         $SQL .= "INTO   lklayoutregiongroup ";
         $SQL .= "       ( ";
         $SQL .= "              LayoutID, ";
         $SQL .= "              RegionID, ";
         $SQL .= "              GroupID, ";
         $SQL .= "              View, ";
         $SQL .= "              Edit, ";
         $SQL .= "              Del ";
         $SQL .= "       ) ";
         $SQL .= " SELECT :layoutid, RegionID, GroupID, View, Edit, Del ";
         $SQL .= "   FROM lklayoutregiongroup ";
         $SQL .= "  WHERE LayoutID = :oldlayoutid ";
         $sth = $dbh->prepare($SQL);
         $sth->execute(array('layoutid' => $newLayoutId, 'oldlayoutid' => $layoutId));
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25028, __('Could not Copy All Layout Region Security'));
         }
         return false;
     }
 }
Esempio n. 25
0
 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;
     }
 }
Esempio n. 26
0
 /**
  * Get unused media entries
  * @param int $userId
  * @return array
  * @throws Exception
  */
 public static function entriesUnusedForUser($userId)
 {
     $media = array();
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('SELECT media.mediaId, media.storedAs, media.type, media.isedited, media.fileSize,
                 SUM(CASE WHEN IFNULL(lklayoutmedia.lklayoutmediaid, 0) = 0 THEN 0 ELSE 1 END) AS UsedInLayoutCount,
                 SUM(CASE WHEN IFNULL(lkmediadisplaygroup.id, 0) = 0 THEN 0 ELSE 1 END) AS UsedInDisplayCount
               FROM `media`
                 LEFT OUTER JOIN `lklayoutmedia`
                 ON lklayoutmedia.mediaid = media.mediaid
                 LEFT OUTER JOIN `lkmediadisplaygroup`
                 ON lkmediadisplaygroup.mediaid = media.mediaid
              WHERE media.userId = :userId
               AND media.type <> \'module\' AND media.type <> \'font\'
             GROUP BY media.mediaid, media.storedAs, media.type, media.isedited');
         $sth->execute(array('userId' => $userId));
         foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
             // Check to make sure it is not used
             if ($row['UsedInLayoutCount'] > 0 || $row['UsedInDisplayCount'] > 0) {
                 continue;
             }
             $media[] = $row;
         }
     } catch (Exception $e) {
         Debug::Error($e->getMessage());
         throw new Exception(__('Cannot get entries'));
     }
     return $media;
 }
Esempio n. 27
0
 /**
  * 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;
     }
 }
Esempio n. 28
0
 /**
  * Set the owner
  * @param int $layoutId
  * @param int $userId
  */
 public static function setOwner($layoutId, $userId)
 {
     $dbh = PDOConnect::init();
     $params = array('userId' => $userId, 'layoutId' => $layoutId);
     $sth = $dbh->prepare('UPDATE `layout` SET userId = :userId WHERE layoutId = :layoutId');
     $sth->execute($params);
     \Xibo\Helper\Log::audit('layout', $layoutId, 'Changing Ownership', $params);
 }
Esempio n. 29
0
}
/*
 * Before we do anything else, lets check to see if we have a settings.php file
 * Without that file we can deduce that
 *  a) This is a first time install
 *  b) This is a corrupt or failed install
 */
if (!file_exists("settings.php")) {
    Kit::Redirect("install.php");
    die;
}
// parse and init the settings.php
Config::Load();
// Test our DB connection through PDO
try {
    PDOConnect::init();
} catch (PDOException $e) {
    die('Database connection problem.');
}
// create a database class instance (legacy)
$db = new database();
if (!$db->connect_db($dbhost, $dbuser, $dbpass)) {
    die('Database connection problem.');
}
if (!$db->select_db($dbname)) {
    die('Database connection problem.');
}
date_default_timezone_set(Config::GetSetting("defaultTimezone"));
// Error Handling (our error handler requires a DB connection
set_error_handler(array(new Debug(), "ErrorHandler"));
// Define an auto-load function
Esempio n. 30
0
 /**
  * End point for jQuery file uploader
  */
 public function JqueryFileUpload()
 {
     $db =& $this->db;
     require_once "3rdparty/jquery-file-upload/XiboUploadHandler.php";
     $type = Kit::GetParam('type', _REQUEST, _WORD);
     Kit::ClassLoader('file');
     $fileObject = new File($db);
     $libraryFolder = Config::GetSetting('LIBRARY_LOCATION');
     // Make sure the library exists
     $fileObject->EnsureLibraryExists();
     // Get Valid Extensions
     Kit::ClassLoader('media');
     $media = new Media($db);
     $validExt = $media->ValidExtensions($type);
     $options = array('db' => $this->db, 'user' => $this->user, 'upload_dir' => $libraryFolder . 'temp/', 'download_via_php' => true, 'script_url' => Kit::GetXiboRoot() . '?p=content&q=JqueryFileUpload', 'upload_url' => Kit::GetXiboRoot() . '?p=content&q=JqueryFileUpload', 'image_versions' => array(), 'accept_file_types' => '/\\.' . implode('|', $validExt) . '$/i');
     // Hand off to the Upload Handler provided by jquery-file-upload
     $handler = new XiboUploadHandler($options);
     // Must commit if in a transaction
     try {
         $dbh = PDOConnect::init();
         $dbh->commit();
     } catch (Exception $e) {
         Debug::LogEntry('audit', 'Unable to commit/rollBack');
     }
     // Must prevent from continuing (framework will try to issue a response)
     exit;
 }