/** * generates a select (drop down) */ public function iSelectTranslate($key, $section, $options = '') { if (isset($this->obj)) { $options = $this->obj->getPropertyOptions($key); } if (empty($options['options'])) { FC::log_warn("iRadio {$key} does not provide options"); return $key . ' (no option)'; } $str = '<select id="i_' . $key . '" name="' . $key . '">'; $i = 1; foreach ($options['options'] as $val => $lbl) { $str .= '<option value="' . $val . '"'; if ($options['value'] == $val) { $str .= ' selected="selected"'; } $str .= ' value="' . $val . '">' . TR::html($section, $lbl) . '</option>'; $i++; } return $str . '</select>'; }
/** * log or display DB errors in the browser */ public function reportError($qry = '') { if (!$this->debug) { return false; } $str = 'DB Error #' . $this->connector->getErrorNo() . ' : ' . $this->connector->getErrorMsg(); switch ($this->debug) { case 1: case 3: FC::log_error($str); if ($qry) { FC::log_error($str); } break; case 2: case 4: echo '<p>' . nl2br(htmlentities($str)); echo '<br /><code>' . htmlentities($qry) . '</code></p>'; break; default: echo '<p>DB DEBUG level undefined</p>'; break; } if ($this->critical) { exit; } }
/** * log or display DB errors in the browser */ public function reportError($qry = '') { if (empty($this->debug)) { return false; } // if critical, should at least show an error code in browser $debug = $this->critical && $this->debug < 2 ? 2 : $this->debug; $html = ''; $str = 'DB Error #' . $this->connector->getErrorNo() . ' : ' . $this->connector->getErrorMsg(); switch ($debug) { case 2: echo '<p>DB Error #' . $this->connector->getErrorNo() . '</p>'; case 1: if ($qry) { FC::log_error($qry); } case 4: FC::log_error($str); break; case 3: if ($qry) { $htm = '<br /><code>' . htmlentities($qry) . '</code>'; } case 5: $htm = nl2br(htmlentities($str)) . $htm; break; default: echo '<p>DB DEBUG level undefined</p>'; break; } echo '<p>' . $htm . '</p>'; if ($this->critical) { exit; } }
/** * change a task status (start, stop, close) or save a new one * will only update the timer panel and reload the task list * (method called by ajax request only) */ public function timerReaction() { $this->jsCode = ''; if ($id = $this->fc->getReqVar('id')) { // start / stop timer $obj = new TaskSummary(); $obj->connectDb(); $obj->setUid($id); $obj->load(); // what action then ? $action = $this->fc->chkReqVar('pause,resume,start,stop,close'); FC::log_debug('loaded task ID=' . $obj->getUid()); switch ($action) { case 'pause': // try to pause if ($this->current && $this->current->getUid() == $id) { // ok, task is actually running TimerModel::stop($id); $this->current->set('stop', APP_SQL_NOW); $this->jsCode .= "clockreport('{$cid}');clockstatus('paused');"; } else { // nope, requested task is not running, show error $this->jsCode = "alert('" . TR::get('error', 'action_failed') . "')"; FC::log_debug('error trying to pause non running task'); } break; case 'resume': case 'start': TimerModel::start($id); $this->current = TaskSummary::loadCurrent(); $this->jsCode = "clockstart();"; break; case 'stop': if (TimerModel::stop($id)) { $this->jsCode = "clockstatus();"; } else { $this->jsCode = "alert('" . TR::get('error', 'action_failed') . "');"; } $this->current = false; break; case 'close': if (TimerModel::stop($id)) { $this->jsCode = "clockstatus();"; $this->current->updateStatus(1); // mark as done $this->current = false; } break; } } else { if ($title = $this->fc->getReqVar('title')) { // creating a new task ? $obj = TaskModel::parse($title, $def, $dte); $obj->connectDb(); if ($this->fc->getReqVar('start')) { $obj->set('deadline', APP_SQL_TODAY); } if ($obj->check($this->switch_id)) { $obj->insert(); } if ($this->fc->chkReqVar('start')) { TimerModel::start($obj->getUid()); $this->current = TaskSummary::loadCurrent(); $this->jsCode = "clockstart();"; } else { $this->current = false; $this->jsCode = "clockstatus();"; } } } $this->jsCode .= 'reloadList();'; $this->setView('include/timer'); $this->view(); return false; }
/** * change task status */ protected function _taskStatus() { $this->current = TaskSummary::loadCurrent(); $arrReload = array(); if ($id = $this->fc->getReqVar('id')) { if ($this->current && $this->current->getUid() != $id) { // we have a running task, but it's not the requested one // so first, we need to stop it. $cid = $this->current->getUid(); TimerModel::stop($cid); // and we'll have to reload the page details later $arrReload[] = $cid; } else { $this->current = new TaskSummary(); $this->current->connectDb(); $this->current->setUid($id); $this->current->load(); } if ($this->current->getUid()) { // -TODO- check rights switch ($this->fc->getReqVar('action')) { case 'pause': // try to pause if ($this->current && $this->current->getUid() == $id) { // ok, task is actually running TimerModel::stop($id); $this->current->set('stop', APP_SQL_NOW); $this->jsCode .= ""; } else { // nope, requested task is not running, show error FC::log_debug('error trying to pause non running task'); header('HTTP/1.0 403 Forbidden'); exit; } $this->setView('iphone/inc_timer'); $this->viewRaw(); break; case 'resume': case 'start': TimerModel::start($id); $this->current = TaskSummary::loadCurrent(); $this->jsCode = "clockstart();"; $this->setView('iphone/inc_timer'); $this->viewRaw(); break; case 'stop': if (TimerModel::stop($id)) { $this->jsCode = "clockstatus();"; } else { $this->jsCode = "alert('" . TR::get('error', 'action_failed') . "');"; } $this->current = false; break; case 'close': if (TimerModel::stop($id)) { $this->jsCode = "clockstatus();"; $this->current->updateStatus(1); // mark as done $this->current = false; } break; } // need to reload newly modified task details $arrReload[] = $id; } return false; } // reaching this point means an error has occured header('HTTP/1.0 404 Not Found'); exit; }
protected function _setObject($key, $data, $class = '', $nkey = '') { if (empty($class)) { if (!$this->isObjectProperty($key, $class, $nkey)) { return false; } } // setting an object FC::log_core_debug(get_class($this) . "->_setObject({$key}, [data], {$class}, {$nkey})"); $obj = new $class(); // set data set with interresting data only $part = array(); foreach ($data as $k => $v) { if (preg_match('/^(' . $nkey . '__|' . $nkey . '::)([a-z0-9_]+)$/', $k, $m)) { $kk = $m[2]; $part[$kk] = $v; } } FC::log_core_debug(' -> found ' . count($part) . ' properties to be set (' . implode(', ', array_keys($part)) . ')'); if (count($part)) { if ($obj->set($part)) { FC::log_core_debug(" => setting " . get_class($obj) . " in {$key}"); $this->data[$key] = $obj; return true; } else { FC::log_core_debug($obj->getAllErrors()); } } return false; }
public function setupTimeZone() { if (!$this->isEmpty('time_zone')) { try { $GLOBALS['config']['datetime']['timezone_user'] = new DateTimeZone($this->get('time_zone')); // FC::log_debug('User::setupTimeZone : new time zone '.$this->get('time_zone')); } catch (Exception $e) { FC::log_error('User::setupTimeZone : unknown time zone (' . $this->get('time_zone') . ')'); } } }
<?php class FC { var $foo; function start() { //print "Requiring file"; require_once 'toy11a.php'; print_r($list); //$f = new Fubar; //print "File required"; //print "list: ". $list; //$f1 = new Fubar; //$f1->bar = "foo"; //print $f1->bar; } } $fc = new FC(); $ctrl = new Controller(); print $fc->start();
public static function getRawTranslation($section, $label, $field = '') { if (!array_key_exists($section, $GLOBALS['lang'])) { FC::log_debug('can not find section ' . $section); return str_replace('_', ' ', $label); } if (array_key_exists($label, $GLOBALS['lang'][$section])) { if (is_array($GLOBALS['lang'][$section][$label])) { return $GLOBALS['lang'][$section][$label][$field]; } else { return $GLOBALS['lang'][$section][$label]; } } else { if (array_key_exists($label, $GLOBALS['lang'][$section])) { if (is_array($GLOBALS['lang'][$section][$label])) { return $GLOBALS['lang'][$section][$label][$field]; } else { return $GLOBALS['lang'][$section][$label]; } } else { FC::log_debug('really can not find section ' . $section); return str_replace('_', ' ', $label); } } }