Пример #1
0
 /**
  * Returns a id->name array
  */
 public static function getFlat($filter = '')
 {
     $db = SqlHandler::getInstance();
     $q = 'SELECT id, name FROM ' . self::$tbl_name . ' WHERE time_deleted IS NULL';
     if ($filter) {
         $q .= ' AND name LIKE "%' . $db->escape($filter) . '%"';
     }
     return $db->getMappedArray($q);
 }
 function getTableDetails($tblname)
 {
     $db = SqlHandler::getInstance();
     $list = $db->getArray('DESCRIBE ' . $db->escape($this->database) . '.' . $db->escape($tblname));
     if (!$list) {
         return false;
     }
     return $list;
 }
Пример #3
0
 public function connect()
 {
     if (!isset(self::$connection)) {
         self::$connection = @new mysqli(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_DB);
         if (self::$connection->connect_error) {
             throw new CriticalFaultException("MySQLi Error:" . self::$connection->connect_error);
         }
     }
     if (self::$connection === false) {
         return false;
     }
     return self::$connection;
 }
Пример #4
0
 function renderJson()
 {
     $res = array('totalRecords' => $this->total_records, 'records' => $this->data);
     //attaches sql debug in the response
     $db = SqlHandler::getInstance();
     if ($db instanceof DatabaseMysqlProfiler) {
         $res['db'] = array('queries' => $db->queries);
     }
     // creates a js snippet which adds the json code as a parameter to named callback function, used for YuiAutocomplete
     if (!empty($_GET['callback'])) {
         // example: YAHOO.util.ScriptNodeDataSource.callbacks[0]        XXX regexp validate string
         return $_GET['callback'] . '(' . json_encode($res) . ');';
     }
     return json_encode($res);
 }
Пример #5
0
 public static function get($id)
 {
     if (!$id || !is_numeric($id)) {
         return false;
     }
     $db = SqlHandler::getInstance();
     $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE id = ?';
     $row = $db->pSelectRow($q, 'i', $id);
     $obj = SqlObject::loadObject($row, __CLASS__);
     if (!$obj) {
         throw new \Exception('bad id ' . $id);
     }
     $obj->episodes = TvEpisode::getAllByOwner($id);
     return $obj;
 }
Пример #6
0
 /**
  * Initializes the list from database
  */
 function init()
 {
     $db = SqlHandler::getInstance();
     //XXX use SqlObject loading
     $q = 'SELECT * FROM tblCategories WHERE categoryType=' . $this->type . ' ';
     if ($this->owner) {
         $q .= 'AND ownerId=' . $this->owner;
     }
     $list = $db->getArray($q);
     foreach ($list as $row) {
         $cat = new CategoryItem($this->type);
         $cat->setId($row['categoryId']);
         $cat->setTitle($row['categoryName']);
         $cat->setOwner($row['ownerId']);
         $cat->setPermissions($row['permissions']);
         $cat->setCreator($row['creatorId']);
         $cat->TimeCreated = new Timestamp($row['timeCreated']);
         $this->addItem($cat);
     }
 }
Пример #7
0
 public function render()
 {
     //available variables in the scope of the view
     if (class_exists('\\cd\\ErrorHandler')) {
         $error = ErrorHandler::getInstance();
     }
     if (class_exists('\\cd\\SessionHandler')) {
         $session = SessionHandler::getInstance();
     }
     if (class_exists('\\cd\\SqlHandler')) {
         $db = SqlHandler::getInstance();
     }
     if (class_exists('\\cd\\XhtmlHeader')) {
         $header = XhtmlHeader::getInstance();
     }
     if (class_exists('\\cd\\XmlDocumentHandler')) {
         $page = XmlDocumentHandler::getInstance();
     }
     if (class_exists('\\cd\\LocaleHandler')) {
         $locale = LocaleHandler::getInstance();
     }
     if (class_exists('\\cd\\TempStore')) {
         $temp = TempStore::getInstance();
     }
     // make reference to calling object available in the namespace of the view
     $caller = $this->caller;
     $file = $page->getCoreDevPath() . $this->template;
     if (!file_exists($file)) {
         // if not built in view, look in app dir
         $file = $this->template;
         if (!file_exists($file)) {
             throw new \Exception('cannot find ' . $this->template);
         }
     }
     ob_start();
     require $file;
     return ob_get_clean();
 }
Пример #8
0
 /** returns insert id */
 public static function pInsert()
 {
     $stmt = self::pExecStmt(func_get_args());
     if ($stmt->rowCount() != 1) {
         $args = func_get_args();
         throw new \Exception('insert fail: ' . $args[0]);
     }
     self::finishMeasure(func_get_args());
     $db = SqlHandler::getInstance();
     return $db->db_handle->lastInsertId();
 }
Пример #9
0
<?php

try {
    $sql = new SqlHandler();
} catch (CriticalFaultException $e) {
    header('Location: ' . APP_WEBSITE . 'unavailable.php?error=' . urlencode($e->getMessage()));
}
try {
    $sql->connect();
} catch (CriticalFaultException $e) {
    header('Location: ' . APP_WEBSITE . 'unavailable.php?error=' . urlencode($e->getMessage()));
}
Пример #10
0
 /**
  * Redirects user to error page
  */
 function showErrorPage()
 {
     $db = SqlHandler::getInstance();
     if ($db instanceof DatabaseMysqlProfiler && $db->getErrorCount()) {
         echo "DEBUG: session->redirect aborted due to error" . ln();
         return;
     }
     js_redirect($this->error_page);
 }
Пример #11
0
 /**
  * Adds a task to the Task Queue
  *
  * @param $_type type of task
  * @param $param
  * @param $param2
  * @return process event id
  */
 static function addTask($type, $param, $param2 = '')
 {
     if (!is_numeric($type)) {
         return false;
     }
     $db = SqlHandler::getInstance();
     $session = SessionHandler::getInstance();
     switch ($type) {
         case TASK_FETCH:
             // downloads media files; enqueue url for download and processing
             //    $param = url
             $q = 'INSERT INTO tblTaskQueue SET timeCreated = NOW(), creatorId = ?, orderType = ?, referId = ?, orderStatus = ?, orderParams = ?';
             return $db->pInsert($q, 'iiiis', $session->id, $type, 0, ORDER_NEW, $param);
         case TASK_UPLOAD:
             // handle HTTP post file upload. is not enqueued
             //    $param is the $_FILES[idx] array
             $exec_time = 0;
             // XXXX FIXME measure
             // THE UPLOAD IS ALREADY PROCESSED BY XhtmlForm upload handler
             $fileId = $param['file_id'];
             $q = 'INSERT INTO tblTaskQueue SET timeCreated = NOW(), creatorId = ?, orderType = ?, referId = ?, orderStatus = ?, orderParams = ?, timeExec = ?, timeCompleted = NOW()';
             return $db->pInsert($q, 'iiiiss', $session->id, $type, $fileId, ORDER_COMPLETED, serialize($param), $exec_time);
             /*
                     case PROCESSQUEUE_AUDIO_RECODE:
                     case PROCESSQUEUE_IMAGE_RECODE:
                     case PROCESSQUEUE_VIDEO_RECODE:
                         //enque file for recoding.
                         //    $param = fileId
                         //    $param2 = destination format (by extension)
                         if (!is_numeric($param)) die;
                         $q = 'INSERT INTO tblTaskQueue SET timeCreated=NOW(),creatorId='.$session->id.',orderType='.$_type.',referId='.$param.',orderStatus='.ORDER_NEW.',orderParams="'.$db->escape($param2).'"';
                         return $db->insert($q);
             
                     case PROCESS_CONVERT_TO_DEFAULT:
                         if (!is_numeric($param)) return false;
                         //convert some media to the default media type, can be used to enqueue a conversion of a PROCESSFETCH before the server
                         //has fetched it & cant know the media type
                         //  $param = eventId we refer to. from this we can extract the future fileId to process
                         //    $param2 = array of additional parameters:
                         //        'callback' = callback URL on process completion (optional)
                         //        'watermark' = URL for watermark file (optional)
                         $q = 'INSERT INTO tblTaskQueue SET timeCreated=NOW(),creatorId='.$session->id.',orderType='.$_type.',referId='.$param.',orderStatus='.ORDER_NEW.',orderParams="'.$db->escape(serialize($param2)).'"';
                         return $db->insert($q);
             
                     case PROCESS_PARSE_AND_FETCH:
                         //parse this resource for further media resources and fetches them
                         // $param = fileId
                         // use to process a uploaded .torrent file & download it's content
                         // or to process a webpage and extract video files from it (including youtube) and download them to the server
                         die('not implemented PROCESS_PARSE_AND_FETCH');
                         break;
             */
         /*
                 case PROCESSQUEUE_AUDIO_RECODE:
                 case PROCESSQUEUE_IMAGE_RECODE:
                 case PROCESSQUEUE_VIDEO_RECODE:
                     //enque file for recoding.
                     //    $param = fileId
                     //    $param2 = destination format (by extension)
                     if (!is_numeric($param)) die;
                     $q = 'INSERT INTO tblTaskQueue SET timeCreated=NOW(),creatorId='.$session->id.',orderType='.$_type.',referId='.$param.',orderStatus='.ORDER_NEW.',orderParams="'.$db->escape($param2).'"';
                     return $db->insert($q);
         
                 case PROCESS_CONVERT_TO_DEFAULT:
                     if (!is_numeric($param)) return false;
                     //convert some media to the default media type, can be used to enqueue a conversion of a PROCESSFETCH before the server
                     //has fetched it & cant know the media type
                     //  $param = eventId we refer to. from this we can extract the future fileId to process
                     //    $param2 = array of additional parameters:
                     //        'callback' = callback URL on process completion (optional)
                     //        'watermark' = URL for watermark file (optional)
                     $q = 'INSERT INTO tblTaskQueue SET timeCreated=NOW(),creatorId='.$session->id.',orderType='.$_type.',referId='.$param.',orderStatus='.ORDER_NEW.',orderParams="'.$db->escape(serialize($param2)).'"';
                     return $db->insert($q);
         
                 case PROCESS_PARSE_AND_FETCH:
                     //parse this resource for further media resources and fetches them
                     // $param = fileId
                     // use to process a uploaded .torrent file & download it's content
                     // or to process a webpage and extract video files from it (including youtube) and download them to the server
                     die('not implemented PROCESS_PARSE_AND_FETCH');
                     break;
         */
         default:
             die('unknown processqueue type');
             return false;
     }
 }
Пример #12
0
require_once 'FileList.php';
require_once 'FileInfo.php';
//project includes:
require_once 'functions_process.php';
require_once 'TaskQueue.php';
//XXX move to core_dev when matured
$page = XmlDocumentHandler::getInstance();
$page->designHead(dirname(__FILE__) . '/design_head.php');
$page->designFoot(dirname(__FILE__) . '/design_foot.php');
$page->setUrl('http://processtest.x/');
$page->setCoreDevInclude($coredev_inc);
///XXX peka på "/path/to/core_dev/core/" katalogen, hör egentligen inte till page handlern men den hör inte till något bra objekt... separat core-dev handler????
$page->setApplicationPath();
$db = SqlFactory::factory('mysql', true);
// enable profiler
SqlHandler::addInstance($db);
//registers the created database connection as the one to use by SqlHandler
//$db->setConfig( array('host' => 'process1.x:44000', 'database' => 'dbProcess', 'username' => 'ml', 'password' => 'xx') );
$db->setConfig(array('host' => 'localhost:44308', 'database' => 'dbProcess2', 'username' => 'root', 'password' => 'xx'));
$page->enableProfiler();
$locale = LocaleHandler::getInstance();
$locale->set('swe');
$session = SessionHandler::getInstance();
$session->setName('savakID');
$session->setTimeout(60 * 60 * 24 * 2);
//keep logged in for 2 days!
$session->setEncryptKey('sdcu7cw897cwhwihwiuh#zaixx7wsxh3hdzsddFDF4ex1g');
$session->allowLogins(true);
$session->allowRegistrations(false);
$page->setUploadPath('/devel/projects/process/uploads/');
$header = XhtmlHeader::getInstance();
Пример #13
0
 static function updatePoll($id, $text, $time_start = '', $time_end = '')
 {
     $add_string = '';
     if (!empty($time_start)) {
         $add_string .= ', time_start = "' . $time_start . '"';
     }
     if (!empty($time_end)) {
         $add_string .= ', time_end = "' . $time_end . '"';
     }
     $db = SqlHandler::getInstance();
     $q = 'UPDATE tblPolls SET text="' . $db->escape($text) . '"' . $add_string . ' WHERE id=' . $id;
     $db->update($q);
 }