示例#1
0
 static function RunSearch($q, $adv = null)
 {
     $scores = array();
     foreach (self::$recipients as $module => $info) {
         $fields = $info[0];
         $obj = utopia::GetInstance($module);
         $pk = $obj->GetPrimaryKey();
         $dataset = $obj->GetDataset();
         while ($row = $dataset->fetch()) {
             $score = 0;
             foreach ($fields as $field) {
                 if (!isset($row[$field])) {
                     continue;
                 }
                 $score += self::SearchCompareScore($q, $row[$field]);
             }
             if ($score > 0) {
                 $scores[] = array($score, $module, $row[$pk], $info);
             }
         }
     }
     if ($adv) {
         foreach ($scores as $k => $s) {
             if ($s[1] != self::$types[$adv]) {
                 unset($scores[$k]);
             }
         }
         //			return call_user_func(self::$types[$adv]['callback'],$q,$scores);
     }
     array_sort_subkey($scores, 0, false);
     return $scores;
 }
示例#2
0
 public static function DrawDashboard()
 {
     // get large widget area
     ob_start();
     uEvents::TriggerEvent('ShowDashboard');
     $largeContent = ob_get_clean();
     if ($largeContent) {
         echo '<div class="dash-large">' . $largeContent . '</div>';
     }
     // get small widget area
     $smallContent = '';
     $w = utopia::GetModulesOf('uDashboardWidget');
     foreach ($w as $wid) {
         $wid = $wid['module_name'];
         $ref = new ReflectionClass($wid);
         ob_start();
         if ($ref->hasMethod('Draw100')) {
             $wid::Draw100();
         } elseif ($ref->hasMethod('Draw50')) {
             $wid::Draw50();
         } elseif ($ref->hasMethod('Draw25')) {
             $wid::Draw25();
         }
         $content = ob_get_clean();
         if (!$content) {
             continue;
         }
         $smallContent .= '<div class="widget-container ' . $wid . '"><h1>' . $wid::GetTitle() . '</h1><div class="module-content">' . $content . '</div></div>';
     }
     if ($smallContent) {
         echo '<div class="dash-small">' . $smallContent . '</div>';
     }
 }
示例#3
0
 static function GetTrail($start = null)
 {
     $obj = utopia::GetInstance('uCMS_List');
     $arr = $obj->GetNestedArray();
     $out = array();
     //TODO: add (Search Results) to end of title if current page is filtered.
     $out[$_SERVER['REQUEST_URI']] = '{utopia.title}';
     // '<a href="'.$_SERVER['REQUEST_URI'].'">{utopia.title}</a>';
     foreach (self::$extras as $a) {
         $out[$a[1]] = $a[0];
         //'<a href="'.$a[1].'">'.$a[0].'</a>';
     }
     $obj = utopia::GetInstance('uCMS_View');
     $row = uCMS_View::findPage();
     do {
         if (!$row) {
             break;
         }
         $url = $obj->GetURL($row['cms_id']);
         $title = $row['nav_text'] ? $row['nav_text'] : $row['title'];
         $out[$url] = $title;
     } while ($row['parent'] && ($row = uCMS_List::findKey($arr, $row['parent'])));
     $build = array();
     foreach ($out as $k => $v) {
         $build[] = '<a href="' . $k . '">' . $v . '</a>';
     }
     $build = array_unique($build);
     if ($start) {
         $build[] = $start;
     }
     if (count($build) < 1) {
         return '';
     }
     return implode(' &gt; ', array_reverse($build));
 }
示例#4
0
 static function DrawData($rec)
 {
     $ret = $rec['content'];
     while (utopia::MergeVars($ret)) {
     }
     return $ret;
 }
示例#5
0
 static function remove_metadata_field()
 {
     $migrated = modOpts::GetOption('metadata_migrated');
     if ($migrated) {
         return;
     }
     try {
         $obj = utopia::GetInstance('uWidgets', false);
         $obj->BypassSecurity(true);
         $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uCustomWidget'));
         while ($row = $ds->fetch()) {
             $pk = $row['widget_id'];
             $meta = utopia::jsonTryDecode($row['__metadata']);
             foreach ($meta as $field => $val) {
                 $obj->UpdateField($field, $val, $pk);
             }
         }
         $obj->BypassSecurity(false);
         $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uCustomWidget'));
     } catch (Exception $e) {
     }
     try {
         $obj = utopia::GetInstance('uWidgets', false);
         $obj->BypassSecurity(true);
         $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTextWidget'));
         while ($row = $ds->fetch()) {
             $pk = $row['widget_id'];
             $meta = utopia::jsonTryDecode($row['__metadata']);
             foreach ($meta as $field => $val) {
                 $obj->UpdateField($field, $val, $pk);
             }
         }
         $obj->BypassSecurity(false);
         $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTextWidget'));
     } catch (Exception $e) {
     }
     try {
         $obj = utopia::GetInstance('uWidgets', false);
         $obj->BypassSecurity(true);
         $ds = database::query('SELECT * FROM tabledef_Widgets WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTwitterWidget'));
         while ($row = $ds->fetch()) {
             $pk = $row['widget_id'];
             $meta = utopia::jsonTryDecode($row['__metadata']);
             foreach ($meta as $field => $val) {
                 $obj->UpdateField($field, $val, $pk);
             }
         }
         $obj->BypassSecurity(false);
         $ds = database::query('UPDATE tabledef_Widgets SET `__metadata` = NULL WHERE `block_type` = ? AND `__metadata` IS NOT NULL', array('uTwitterWidget'));
     } catch (Exception $e) {
     }
     $ds = database::query('SHOW TABLES');
     while ($t = $ds->fetch(PDO::FETCH_NUM)) {
         try {
             database::query('ALTER TABLE ' . $t[0] . ' DROP `__metadata`');
         } catch (Exception $e) {
         }
     }
     modOpts::SetOption('metadata_migrated', true);
 }
示例#6
0
 public static function CreateLinkMenu($module = null)
 {
     $cm = utopia::GetCurrentModule();
     if ($module === null) {
         $module = $cm;
     }
     if (isset(self::$done[$module])) {
         return;
     }
     self::$done[$module] = true;
     $cmAdmin = is_subclass_of($cm, 'iAdminModule');
     $modules = utopia::GetChildren($module);
     $highestpos = 0;
     foreach ($modules as $mid => $children) {
         if ($cmAdmin && !is_subclass_of($mid, 'iAdminModule')) {
             continue;
         }
         if (!$cmAdmin && is_subclass_of($mid, 'iAdminModule')) {
             continue;
         }
         foreach ($children as $child) {
             if (isset($child['callback'])) {
                 continue;
             }
             if (isset($child['fieldLinks']) && $mid !== $cm) {
                 continue;
             }
             if (uEvents::TriggerEvent('CanAccessModule', $mid) === FALSE) {
                 continue;
             }
             if ($module !== $cm && $child['parent'] === '/') {
                 continue;
             }
             $parent = '_modlinks_';
             if (isset($child['parent']) && $child['parent'] !== '/') {
                 $parent .= $child['parent'];
             }
             $obj = utopia::GetInstance($mid);
             $position = $obj->GetSortOrder();
             if (isset($child['fieldLinks']) && $mid === $cm) {
                 $position = 0;
             }
             if ($position > $highestpos) {
                 $highestpos = $position;
             }
             uMenu::AddItem($parent . $mid, $obj->GetTitle(), $obj->GetURL(), $parent, null, $position);
         }
         self::CreateLinkMenu($mid);
     }
     if ($module === $cm) {
         // add separators
         $i = -10001;
         while ($i < $highestpos) {
             uMenu::AddItem('_sep_' . $i, '', '', '_modlinks_', null, $i);
             $i = $i + 1000;
         }
     }
 }
示例#7
0
 public static function GetImageField($originalValue, $pkVal, $value, $rec, $fieldName)
 {
     if (!$originalValue) {
         return '';
     }
     $o = utopia::GetInstance($rec['_module']);
     $size = $o->GetFieldProperty($fieldName, 'size');
     return self::GetImage($originalValue, $size);
 }
示例#8
0
 static function RunPopup()
 {
     utopia::SetTitle('Browse Media');
     uEvents::RemoveCallback('ProcessDomDocument', 'uAdminBar::ProcessDomDocument');
     utopia::UseTemplate(TEMPLATE_BLANK);
     utopia::$noSnip = true;
     $o = utopia::GetInstance('fileManager');
     $o->_RunModule();
 }
示例#9
0
 public function RunModule()
 {
     // button to generate primary menu from old code
     // 'parent' of uCMS should no longer be used anywhere
     return;
     $obj = utopia::GetInstance('uCMS_List');
     $rel = $obj->GetNestedArray();
     $rows = $this->GetDataset()->fetchAll();
 }
示例#10
0
 /**
  * Get path to cache file
  * 
  * @param $identifiers Unique information about this data, used to generate hash
  * @return absolute path to cache file
  */
 private static function getPath($identifiers)
 {
     $cachePath = PATH_ABS_CORE . '.cache/';
     $checksum = utopia::checksum($identifiers);
     $cachePath .= substr($checksum, 0, 3) . '/' . substr($checksum, 3, 3) . '/';
     if (!file_exists($cachePath)) {
         mkdir($cachePath, 0777, true);
     }
     return $cachePath . $checksum;
 }
示例#11
0
 static function GetLink($module, $field, $pk, $filename = NULL)
 {
     if ($filename === NULL) {
         $obj = utopia::GetInstance($module);
         $rec = $obj->LookupRecord($pk);
         $filename = $rec[$field . '_filename'];
     }
     $o = utopia::GetInstance(__CLASS__);
     return $o->GetURL(array('module' => $module, 'field' => $field, 'pk' => $pk, 'filename' => $filename));
 }
示例#12
0
 public static function Draw25()
 {
     if (modOpts::GetOption('site_online')) {
         return;
     }
     if (!uUserRoles::IsAdmin()) {
         return;
     }
     $modOptsObj = utopia::GetInstance('modOpts');
     $row = $modOptsObj->LookupRecord('site_online');
     echo '<p>This website is currently offline. Go Online? ' . $modOptsObj->GetCell('value', $row) . '</p>';
 }
示例#13
0
 static function ProcessDomDocument($obj, $event, $templateDoc)
 {
     if (is_subclass_of(utopia::GetCurrentModule(), 'iAdminModule')) {
         return;
     }
     $html = self::DrawAdminBar();
     if (!$html) {
         return;
     }
     $body = $templateDoc->getElementsByTagName('body')->item(0);
     $node = $templateDoc->createDocumentFragment();
     $node->appendXML($html);
     $body->appendChild($node);
 }
示例#14
0
 public static function uCMS_publish_update()
 {
     $done = modOpts::GetOption('cms_publish_update');
     if ($done) {
         return;
     }
     $o = utopia::GetInstance('uCMS_Edit');
     $o->BypassSecurity(true);
     $ds = $o->GetDataset(array('{content_published_time} > {content_time}'));
     while ($row = $ds->fetch()) {
         $o->UpdateFieldRaw('content_published_time', '`content_time`', $row['cms_id']);
     }
     $o->BypassSecurity(false);
     modOpts::SetOption('cms_publish_update', true);
 }
示例#15
0
 public static function LinkFavicon($obj, $event, $templateDoc)
 {
     // first check template, then check root.
     $iconPaths = array();
     $iconPaths[] = utopia::GetTemplateDir(false) . 'favicon.ico';
     $iconPaths[] = PATH_ABS_ROOT . 'favicon.ico';
     $iconPaths[] = PATH_ABS_CORE . 'favicon.ico';
     $head = $templateDoc->getElementsByTagName('head')->item(0);
     foreach ($iconPaths as $iconPath) {
         if (file_exists($iconPath)) {
             $node = $templateDoc->createElement('link');
             $node->setAttribute('rel', 'shortcut icon');
             $node->setAttribute('href', utopia::GetRelativePath($iconPath));
             $head->appendChild($node);
             return;
         }
     }
 }
示例#16
0
 public static function ShowNotices()
 {
     // is redirect issued?  If so, don't draw now.
     foreach (headers_list() as $h) {
         if (preg_match('/^location:/i', $h)) {
             return;
         }
     }
     if (!utopia::UsingTemplate() && !AjaxEcho()) {
         return;
     }
     if (!isset($_SESSION['notices'])) {
         return;
     }
     $scripts = implode(PHP_EOL, $_SESSION['notices']);
     $_SESSION['notices'] = array();
     if (!AjaxEcho($scripts)) {
         uJavascript::AddText('$(function(){' . $scripts . '});');
     }
 }
示例#17
0
 public function RunModule()
 {
     uEvents::TriggerEvent('InitSitemap');
     $grp = isset($_GET['group']) ? $_GET['group'] : '';
     if (!isset(self::$items[$grp])) {
         utopia::PageNotFound();
     }
     utopia::CancelTemplate();
     header('Content-Type: application/xml', true);
     echo '<?xml version="1.0" encoding="UTF-8"?>';
     echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
     foreach (self::$items[$grp] as $entry) {
         echo '<url>';
         foreach ($entry as $k => $v) {
             echo "\t<{$k}>{$v}</{$k}>";
         }
         echo '</url>';
     }
     echo '</urlset>';
     die;
 }
示例#18
0
 private static function &_query($query, $args = NULL)
 {
     $false = FALSE;
     if (empty($query)) {
         return $false;
     }
     if (!isset($GLOBALS['sql_query_count'])) {
         $GLOBALS['sql_query_count'] = 0;
     } else {
         $GLOBALS['sql_query_count']++;
     }
     if (utopia::DebugMode()) {
         $tID = 'QRY' . $GLOBALS['sql_query_count'] . ': ' . $query;
         timer_start($tID, $args);
     }
     $pdo = self::connect();
     $pdo->reset();
     if (is_array($args)) {
         foreach ($args as $a) {
             $pdo->addByVal($a, self::getType($a));
         }
     }
     try {
         self::$queryCount++;
         $stm = $pdo->call($query);
         $stm->setFetchMode(PDO::FETCH_ASSOC);
     } catch (Exception $e) {
         if (utopia::DebugMode()) {
             $timetaken = timer_end($tID);
         }
         throw $e;
     }
     if (utopia::DebugMode()) {
         $timetaken = timer_end($tID);
     }
     return $stm;
 }
示例#19
0
 public static function TriggerEvent($eventName, $object = null, $eventData = array())
 {
     $module = null;
     if (is_object($object)) {
         $module = get_class($object);
     }
     if (is_string($object)) {
         $module = $object;
         $object = utopia::GetInstance($object);
     }
     $module = strtolower($module);
     $eventName = strtolower($eventName);
     if (!isset(self::$callbacks[$eventName])) {
         return TRUE;
     }
     $process = array_unique(array($module, ''));
     if (!is_array($eventData)) {
         $eventData = array($eventData);
     }
     $eventData = array_merge(array(&$object, $eventName), $eventData);
     // accumulate all handlers
     $handlers = array();
     foreach ($process as $module) {
         if (!isset(self::$callbacks[$eventName][$module])) {
             continue;
         }
         $handlers = array_merge($handlers, self::$callbacks[$eventName][$module]);
     }
     // sort handlers
     array_sort_subkey($handlers, 'order');
     // execute handlers, break if any return FALSE;
     $return = true;
     foreach ($handlers as $callback) {
         $return = $return && call_user_func_array($callback['callback'], $eventData) !== FALSE;
     }
     return $return;
 }
示例#20
0
 static function Init()
 {
     $obj = utopia::GetInstance(__CLASS__);
     return array($obj->GetAjaxPath(), $obj->GetAjaxUploadPath());
 }
示例#21
0
 public function ShowData()
 {
     //check pk and ptable are set up
     if (is_empty($this->GetTabledef())) {
         ErrorLog('Primary table not set up for ' . get_class($this));
         return;
     }
     echo '<h1>' . $this->GetTitle() . '</h1>';
     echo '{list.' . get_class($this) . '}';
     $row = null;
     $num_rows = 0;
     if (!isset($_GET['_n_' . $this->GetModuleId()])) {
         $this->GetLimit($limit, $page);
         $dataset = $this->GetDataset();
         $num_rows = $dataset->CountRecords();
         $row = $dataset->GetPage($page, $limit)->fetch();
     }
     $pagination = '';
     $this->GetLimit($limit);
     if ($limit) {
         $pages = max(ceil($num_rows / $limit), 1);
         ob_start();
         utopia::OutputPagination($pages, '_p_' . $this->GetModuleId());
         $pagination = ob_get_clean();
     }
     $records = $num_rows == 0 ? "There are no records to display." : 'Total Rows: ' . $num_rows;
     $pager = '<div class="right">' . $pagination . '</div>';
     uEvents::TriggerEvent('OnShowDataDetail', $this);
     if ($this->flag_is_set(ALLOW_DELETE) && $row) {
         $fltr =& $this->FindFilter($this->GetPrimaryKey(), ctEQ, itNONE);
         $delbtn = $this->GetDeleteButton($this->GetFilterValue($fltr['uid']), 'Delete Record');
         utopia::AppendVar('footer_left', $delbtn);
     }
     //		if (!$this->IsNewRecord()) { // records exist, lets get the first.
     // pagination?
     //			if (mysql_num_rows($result) > 1) {
     // multiple records exist in this set, sort out pagination
     //			}
     //		}
     $order = $this->GetSortOrder();
     $extraCount = 1;
     $secCount = count($this->layoutSections);
     foreach ($this->layoutSections as $sectionID => $sectionInfo) {
         $out = '';
         if ($secCount > 1) {
             $sectionName = $sectionInfo['title'];
             if ($sectionName === '') {
                 if ($sectionID === 0) {
                     $SN = 'General';
                 } else {
                     $SN = "Extra ({$extraCount})";
                     $extraCount++;
                 }
             } else {
                 $SN = ucwords($sectionName);
             }
             $out .= '<h2>' . $SN . '</h2>';
         }
         if (!$this->isAjax) {
             $out .= '<form class="uf" action="" onsubmit="this.action = window.location" method="post">';
         }
         $out .= "<div class=\"table-wrapper\"><table class=\"module-content layoutDetailSection\">";
         $fields = $this->GetFields(true, $sectionID);
         $hasFieldHeaders = false;
         foreach ($fields as $fieldName => $fieldData) {
             $hasFieldHeaders = $hasFieldHeaders || !empty($fieldData['visiblename']);
         }
         $fieldCount = count($fields);
         foreach ($fields as $fieldName => $fieldData) {
             $targetUrl = $this->GetTargetUrl($fieldName, $row);
             $out .= "<tr>";
             if ($hasFieldHeaders) {
                 $out .= "<td class=\"fld\">" . $fieldData['visiblename'] . "</td>";
             }
             $out .= '<td>' . $this->GetCell($fieldName, $row, $targetUrl) . '</td>';
             $out .= "</tr>";
         }
         $out .= "</table></div>";
         if (!$this->isAjax) {
             $out .= '</form>';
         }
         echo $out;
     }
     if ($num_rows > 1) {
         echo '<div class="oh"><b>' . $records . '</b>' . $pager . '</div>';
     }
 }
示例#22
0
 static function DrawToggleSwitch($fieldName, $inputType, $defaultValue = '', $possibleValues = NULL, $attributes = NULL, $noSubmit = FALSE)
 {
     return utopia::DrawInput($fieldName, itCHECKBOX, $defaultValue, $possibleValues, $attributes, $noSubmit);
 }
示例#23
0
function ProtectedScript()
{
    if ($_SERVER['SCRIPT_NAME'] == $_SERVER['REQUEST_URI']) {
        utopia::CancelTemplate();
        die("Protected Script\nCannot access directly");
    }
}
示例#24
0
 static function OutputPagination($pages, $pageKey = 'page', $spread = 2)
 {
     //$pages $pageKey
     if ($pages <= 1) {
         return 1;
     }
     $parsed = parse_url($_SERVER['REQUEST_URI']);
     $args = isset($parsed['query']) ? $parsed['query'] : '';
     if (is_string($args)) {
         parse_str($args, $args);
     }
     if (get_magic_quotes_gpc()) {
         $args = utopia::stripslashes_deep($args);
     }
     $page = isset($args[$pageKey]) ? $args[$pageKey] : 0;
     echo '<ul class="pagination">';
     if ($page > 0) {
         // previous
         $args[$pageKey] = $page - 1;
         $rel = array('prev');
         if (!$args[$pageKey]) {
             unset($args[$pageKey]);
         }
         if ($page - 1 == 0) {
             $rel[] = 'first';
         }
         echo '<li class="previous"><a rel="' . implode(' ', $rel) . '" class="btn uPaginationLink" href="' . $parsed['path'] . ($args ? '?' . http_build_query($args) : '') . '">Previous</a></li>';
     }
     $prespace = false;
     $postspace = false;
     for ($i = 0; $i < $pages; $i++) {
         $args[$pageKey] = $i;
         $rel = array();
         if (!$args[$pageKey]) {
             unset($args[$pageKey]);
         }
         if ($i < $page - $spread && $i != 0) {
             if (!$prespace) {
                 echo '<li>...</li>';
             }
             $prespace = true;
             continue;
         }
         if ($i > $page + $spread && $i != $pages - 1) {
             if (!$postspace) {
                 echo '<li>...</li>';
             }
             $postspace = true;
             continue;
         }
         if ($i == $page - 1) {
             $rel[] = 'prev';
         }
         if ($i == $page + 1) {
             $rel[] = 'next';
         }
         if ($i == 0) {
             $rel[] = 'first';
         }
         if ($i == $pages - 1) {
             $rel[] = 'last';
         }
         echo '<li><a rel="' . implode(' ', $rel) . '" class="btn uPaginationLink" href="' . $parsed['path'] . ($args ? '?' . http_build_query($args) : '') . '">' . ($i + 1) . '</a></li>';
     }
     if ($page < $pages - 1) {
         // next
         $args[$pageKey] = $page + 1;
         $rel = array('next');
         if ($page + 1 == $pages - 1) {
             $rel[] = 'last';
         }
         echo '<li class="next"><a rel="' . implode(' ', $rel) . '" class="btn uPaginationLink" href="' . $parsed['path'] . ($args ? '?' . http_build_query($args) : '') . '">Next</a></li>';
     }
     echo '</ul>';
     return $page + 1;
 }
示例#25
0
 public static function GetModules()
 {
     $modules = utopia::GetModulesOf('iRestrictedAccess');
     foreach ($modules as $k => $v) {
         $modules[$k] = $k;
     }
     foreach (self::$linked as $k => $mods) {
         // unset all mods
         foreach ($mods as $m) {
             unset($modules[$m]);
         }
         // add k to modules
         $modules[$k] = $k;
     }
     // remove custom roles
     foreach (self::$customRoles as $k => $c) {
         unset($modules[$k]);
     }
     return $modules;
 }
示例#26
0
$(function(){
	if ($('nav ul li').length) {
		$(document).on('click touchstart','nav .icon-menu',function() { $('body').toggleClass('open'); return false; });
	}
});

utopia.Initialise.add(InitCombo);
function InitCombo() {
	$('.inputtype-combo').select2({adaptDropdownCssClass:function(c){return c;}});
}
</script>
</head>
<body class="u-admin">

<header><?php 
$o = utopia::GetInstance('UserProfileDetail');
$r = $o->LookupRecord();
if ($r) {
    echo '<span id="user_welcome"><i class="icon-user"></i> Hi, ' . $r['visible_name'] . ' | </span>';
}
echo '<a href="{home_url}">Website</a>';
if ($r) {
    echo ' | {logout}';
}
?>
</header>
<div id="contentWrap">
	<nav>
		<span class="icon-menu mobile"></span>
		{UTOPIA.modlinks}
	</nav>
示例#27
0
    $row['module_name']::Initialise();
    timer_end('Init: ' . $row['module_name']);
}
timer_end('Static Initialise');
uConfig::DefineConfig();
uConfig::ValidateConfig();
uEvents::TriggerEvent('ConfigDefined');
timer_start('Before Init');
uEvents::TriggerEvent('BeforeInit');
timer_end('Before Init');
timer_start('Table Initialise');
uTableDef::TableExists(null);
// cache table exists
$allmodules = utopia::GetModulesOf('uTableDef');
foreach ($allmodules as $row) {
    // must run second due to requiring GLOB_MOD to be setup fully
    timer_start('Init: ' . $row['module_name']);
    $obj = utopia::GetInstance($row['module_name']);
    $obj->AssertTable();
    // setup Parents
    timer_end('Init: ' . $row['module_name']);
}
timer_end('Table Initialise');
define('INIT_COMPLETE', TRUE);
timer_start('After Init');
uEvents::TriggerEvent('InitComplete');
uEvents::TriggerEvent('AfterInit');
timer_end('After Init');
if ($_SERVER['HTTP_HOST'] !== 'cli') {
    utopia::UseTemplate(TEMPLATE_DEFAULT);
}
示例#28
0
 public static function GetCurrentUser()
 {
     $o = utopia::GetInstance(__CLASS__);
     return $o->LookupRecord();
 }
示例#29
0
 public function UpdateField($fieldName, $newValue, &$pkVal = NULL, $fieldType = NULL)
 {
     $this->AssertTable();
     uEvents::TriggerEvent('BeforeUpdateField', $this, array($fieldName, $newValue, &$pkVal, $fieldType));
     //AjaxEcho('//'.str_replace("\n",'',get_class($this)."@UpdateField($fieldName,,$pkVal)\n"));
     if ($fieldType === NULL) {
         $fieldType = $this->fields[$fieldName]['type'];
     }
     if (is_array($newValue)) {
         $newValue = json_encode($newValue);
     }
     if ($newValue) {
         switch ($fieldType) {
             case ftRAW:
                 break;
             case ftDATE:
             case ftTIME:
             case ftDATETIME:
                 // datetime
             // datetime
             case ftTIMESTAMP:
                 $parsed = utopia::strtotime($newValue);
                 $newValue = $newValue == '' ? 'NULL' : date('Y-m-d H:i:s', $parsed);
                 break;
             case ftFLOAT:
                 // float
             // float
             case ftDECIMAL:
                 $l = setlocale(LC_ALL, 'en_US');
                 $newValue = floatval($newValue);
                 setlocale(LC_ALL, $l);
                 break;
             case ftBOOL:
                 // bool
             // bool
             case ftPERCENT:
                 // percent
             // percent
             case ftCURRENCY:
                 // currency
             // currency
             case ftNUMBER:
                 $newValue = $newValue === '' ? '' : preg_replace('/[^0-9\\.-]/', '', $newValue);
                 break;
         }
     }
     if (($newValue === '' || $newValue === NULL) && $this->GetFieldProperty($fieldName, 'null') !== SQL_NOT_NULL) {
         $newValue = NULL;
     }
     $updateQry = array();
     $raw = $fieldType == ftRAW;
     $args = array();
     if ($pkVal === NULL) {
         $query = 'INSERT INTO ' . $this->tablename . ' (`' . $fieldName . '`) VALUES (' . ($raw ? $newValue : '?') . ')';
         if (!$raw) {
             $args[] = $newValue;
         }
     } else {
         $query = 'UPDATE ' . $this->tablename . ' SET `' . $fieldName . '` = ' . ($raw ? $newValue : '?') . ' WHERE `' . $this->GetPrimaryKey() . '` = ?';
         if (!$raw) {
             $args[] = $newValue;
         }
         $args[] = $pkVal;
     }
     database::query($query, $args);
     if ($fieldName == $this->GetPrimaryKey() && $newValue !== NULL) {
         // this allows us to get the real evaluated value of the new primary key
         $stm = database::query('SELECT ? AS new_pk', array($newValue));
         $row = $stm->fetch();
         $pkVal = $row['new_pk'];
     } elseif ($pkVal === NULL) {
         $pkVal = database::connect()->lastInsertId();
     }
     uEvents::TriggerEvent('AfterUpdateField', $this, array($fieldName, $newValue, &$pkVal, $fieldType));
 }
示例#30
0
 public static function SetOption($ident, $value)
 {
     $obj = utopia::GetInstance(__CLASS__);
     if (self::GetCachedItem($ident) === false) {
         $obj->BypassSecurity(true);
         $obj->UpdateField('ident', $ident);
         $obj->BypassSecurity(false);
     }
     $obj->BypassSecurity(true);
     $obj->UpdateField('value', $value, $ident);
     $obj->BypassSecurity(false);
     self::SetCacheValue($ident, $value);
 }