Exemplo n.º 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;
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 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));
 }
Exemplo n.º 4
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;
         }
     }
 }
Exemplo n.º 5
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();
 }
Exemplo n.º 6
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();
 }
Exemplo n.º 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);
 }
Exemplo n.º 8
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));
 }
Exemplo n.º 9
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>';
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 public static function csv()
 {
     $obj = utopia::GetInstance(utopia::GetCurrentModule());
     $title = $obj->GetTitle();
     $fields = $obj->fields;
     $layoutSections = $obj->layoutSections;
     $fullOut = '';
     // field headers
     $out = array();
     foreach ($fields as $fieldAlias => $fieldData) {
         if (!$fieldData['visiblename']) {
             continue;
         }
         $out[] = $fieldData['visiblename'];
     }
     $fullOut .= '"' . join('","', $out) . "\"\n";
     // rows
     $dataset = $obj->GetDataset();
     $pk = $obj->GetPrimaryKey();
     $i = 0;
     while ($row = $dataset->fetch()) {
         $i++;
         $out = array();
         foreach ($fields as $fieldAlias => $fieldData) {
             if (!$fieldData['visiblename']) {
                 continue;
             }
             $data = strip_tags(trim($obj->PreProcess($fieldAlias, $row[$fieldAlias], $row[$pk])));
             if (empty($data)) {
                 $data = '';
             }
             $out[] = preg_replace('/"/', '""', $data);
         }
         $fullOut .= '"' . join('","', $out) . "\"\n";
     }
     $etag = utopia::checksum($fullOut);
     utopia::Cache_Output($fullOut, $etag, 'text/csv', $title . '.csv');
 }
Exemplo n.º 12
0
 public static function GetUserRole()
 {
     uUserLogin::TryLogin();
     if (!isset($_SESSION['current_user'])) {
         return FALSE;
     }
     if (!self::$roleCache) {
         $obj = utopia::GetInstance('uUsersList');
         $obj->BypassSecurity(true);
         $user = $obj->LookupRecord(array('user_id' => $_SESSION['current_user']), true);
         $obj->BypassSecurity(false);
         if ($user['_roles_pk'] === NULL) {
             return FALSE;
         }
         $obj = utopia::GetInstance('uUserRoles');
         $obj->BypassSecurity(true);
         $role = $obj->LookupRecord($user['_roles_pk'], true);
         // clear fixed filters
         $obj->BypassSecurity(false);
         self::$roleCache = array($role['role_id'], utopia::jsonTryDecode($role['allow']));
     }
     return self::$roleCache;
 }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
0
 static function DrawData($rec)
 {
     if (!$rec['module'] || !class_exists($rec['module'])) {
         return $rec['no_rows'];
     }
     if (!($instance = utopia::GetInstance($rec['module'], false))) {
         return 'Could not load Data Source';
     }
     $instance->_SetupParents();
     $instance->_SetupFields();
     // clear filters
     $rec['clear_filter'] = (array) utopia::jsonTryDecode($rec['clear_filter']);
     foreach ($rec['clear_filter'] as $uid) {
         $instance->RemoveFilter($uid);
     }
     // add filters
     utopia::MergeVars($rec['filter']);
     if ($rec['filter']) {
         $instance->AddFilter($rec['filter'], ctCUSTOM);
     }
     // add Order
     utopia::MergeVars($rec['order']);
     if ($rec['order']) {
         $instance->ordering = NULL;
         $instance->AddOrderBy($rec['order']);
     }
     $dataset = $instance->GetDataset();
     // init limit
     utopia::MergeVars($rec['limit']);
     $rec['limit'] = trim($rec['limit']);
     $instance->GetLimit($limit, $page);
     // page is governed by a different query arg for widgets, below
     $page = stripos($rec['content'], '{pagination}') !== FALSE && isset($_GET['_p_' . $rec['block_id']]) ? $_GET['_p_' . $rec['block_id']] : 0;
     $offset = $limit * $page;
     if ($rec['limit']) {
         if (strpos($rec['limit'], ',') === FALSE) {
             $limit = $rec['limit'];
             $offset = $limit * $page;
         } else {
             list($offset, $limit) = explode(',', $rec['limit']);
             $offset = trim($offset);
             $limit = trim($limit);
         }
     }
     if (!($total = $dataset->CountRecords())) {
         return $rec['no_rows'];
     }
     // get rows
     if ($offset > $total) {
         return $rec['no_rows'];
     }
     // get content
     $content = $append = $prepend = '';
     $html = str_get_html($rec['content'], true, true, DEFAULT_TARGET_CHARSET, false);
     $ele = '';
     if ($html) {
         $ele = $html->find('._ri', 0);
         if ($ele) {
             $ele = $ele->innertext;
         } else {
             $ele = $html->find('._r', 0);
             if ($ele) {
                 $ele = $ele->outertext;
             } else {
                 $ele = '';
             }
         }
     } else {
         $html = $rec['content'];
     }
     $repeatable = $html;
     if ($ele) {
         // found a repeatable element
         // split content at this element. prepare for apend and prepend.
         list($append, $prepend) = explode($ele, $repeatable);
         $repeatable = $ele;
     }
     $dataset->GetOffset($offset, $limit);
     while ($row = $dataset->fetch()) {
         $c = $repeatable;
         $instance->MergeFields($c, $row);
         $content .= $c;
     }
     $ret = $append . $content . $prepend;
     // process full doc
     $ret = str_ireplace('{total}', $total, $ret);
     if ($page !== NULL && is_numeric($limit)) {
         $pages = max(ceil($total / $limit), 1);
         ob_start();
         $cPage = utopia::OutputPagination($pages, '_p_' . $rec['block_id']);
         $ret = str_ireplace('{pagination}', ob_get_clean(), $ret);
         $ret = str_ireplace('{pages}', $pages, $ret);
         $ret = str_ireplace('{current_page}', $cPage, $ret);
     }
     while (utopia::MergeVars($ret)) {
     }
     return $ret;
 }
Exemplo n.º 15
0
 static function Launcher($module = NULL)
 {
     if ($module == NULL) {
         $module = self::GetCurrentModule();
     }
     if (!utopia::ModuleExists($module)) {
         utopia::PageNotFound();
     }
     utopia::SetVar('current_module', $module);
     self::QueueLauncher($module);
     $currentModule = reset(self::$launchers);
     do {
         $obj = utopia::GetInstance($currentModule);
         utopia::SetVar('title', $obj->GetTitle());
         // run module
         timer_start('Run Module: ' . $currentModule);
         $obj->_RunModule();
         timer_end('Run Module: ' . $currentModule);
     } while ($currentModule = next(self::$launchers));
 }
Exemplo n.º 16
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>
Exemplo n.º 17
0
    public static function LoginForm()
    {
        if (self::IsLoggedIn()) {
            return;
        }
        ?>
<div class="login-wrap widget-container">
			<h1>Log In</h1>
			<form class="module-content" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
" method="POST">
			<div class="form-field">
			<label for="__login_u">Email/Username</label>{login_user}
			</div>
			<div class="form-field">
			<label for="__login_p">Password</label>{login_pass}
			</div>
			<label><input type="checkbox" value="1" name="remember_me" /> Remember Me</label><?php 
        $o = utopia::GetInstance('uResetPassword');
        echo utopia::DrawInput('', itSUBMIT, 'Log In', null, array('class' => 'right'));
        echo '<a href="' . $o->GetURL(null) . '" class="forgotten-password">Forgotten Password?</a>';
        echo '</form><script type="text/javascript">$(function (){$(\'#__login_u\').focus()})</script>';
        uEvents::TriggerEvent('LoginButtons');
        echo '</div>';
        // register
        uEvents::TriggerEvent('AfterShowLogin');
    }
Exemplo n.º 18
0
 public static function GetCurrentUser()
 {
     $o = utopia::GetInstance(__CLASS__);
     return $o->LookupRecord();
 }
Exemplo n.º 19
0
 static function Init()
 {
     $obj = utopia::GetInstance(__CLASS__);
     return array($obj->GetAjaxPath(), $obj->GetAjaxUploadPath());
 }
Exemplo n.º 20
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);
 }
Exemplo n.º 21
0
 public static function RunChild()
 {
     $o = utopia::GetInstance(__CLASS__);
     $o->RunModule();
 }
Exemplo n.º 22
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);
}
Exemplo n.º 23
0
 static function GetTemplate($id)
 {
     $template = NULL;
     while ($id != NULL) {
         $obj = utopia::GetInstance('uCMS_View');
         $rec = $obj->LookupRecord($id);
         if ($rec['template']) {
             $template = $rec['template'];
             break;
         }
         $id = $rec['parent'];
     }
     if (!$template) {
         return TEMPLATE_DEFAULT;
     }
     return $template;
 }
Exemplo n.º 24
0
 static function DrawWidget($rec)
 {
     $obj = utopia::GetInstance('uWidgets', false);
     if (!is_array($rec)) {
         if (self::StaticWidgetExists($rec)) {
             return call_user_func(self::$staticWidgets[$rec]);
         }
         $obj->BypassSecurity(true);
         $rec = $obj->LookupRecord(array('block_id' => $rec), true);
         $obj->BypassSecurity(false);
     }
     if (!$rec || !isset($rec['block_type']) || !$rec['block_type'] || !class_exists($rec['block_type'])) {
         return '';
     }
     $obj->InitInstance($rec['block_type']);
     // init and re-request
     $obj->BypassSecurity(true);
     $rec = $obj->LookupRecord($rec['widget_id'], true);
     $obj->BypassSecurity(false);
     $content = call_user_func(array($rec['block_type'], 'DrawData'), $rec);
     $ret = '<div class="uWidget uWidget-' . $rec['block_id'] . '">' . $content . '</div>';
     return $ret;
 }
Exemplo n.º 25
0
 public function ProcessDomDocument($o, $e, $doc)
 {
     $head = $doc->getElementsByTagName('head')->item(0);
     // add OG protocol
     if (isset($_GET['news_id'])) {
         $rec = $this->LookupRecord($_GET['news_id']);
         $img = 'http://' . utopia::GetDomainName() . uBlob::GetLink(get_class($this), 'image', $rec['news_id']);
         $meta = $doc->createElement('meta');
         $meta->setAttribute('property', 'og:title');
         $meta->setAttribute('content', $rec['heading']);
         $head->appendChild($meta);
         $meta = $doc->createElement('meta');
         $meta->setAttribute('property', 'og:type');
         $meta->setAttribute('content', 'article');
         $head->appendChild($meta);
         $meta = $doc->createElement('meta');
         $meta->setAttribute('property', 'og:url');
         $meta->setAttribute('content', 'http://' . utopia::GetDomainName() . $_SERVER['REQUEST_URI']);
         $head->appendChild($meta);
         if ($rec['image']) {
             // image exists?
             $meta = $doc->createElement('meta');
             $meta->setAttribute('property', 'og:image');
             $meta->setAttribute('content', $img);
             $head->appendChild($meta);
         }
         $meta = $doc->createElement('meta');
         $meta->setAttribute('property', 'og:site_name');
         $meta->setAttribute('content', modOpts::GetOption('site_name'));
         $head->appendChild($meta);
         $meta = $doc->createElement('meta');
         $meta->setAttribute('property', 'og:description');
         $meta->setAttribute('content', $rec['description']);
         $head->appendChild($meta);
     }
     // add RSS link
     $rssobj = utopia::GetInstance('module_NewsRSS');
     $link = $doc->createElement('link');
     $link->setAttribute('rel', 'alternate');
     $link->setAttribute('type', 'application/atom+xml');
     $link->setAttribute('title', modOpts::GetOption('site_name') . ' News Feed');
     $link->setAttribute('href', $rssobj->GetURL());
     $head->appendChild($link);
 }
Exemplo n.º 26
0
 public function GetTargetFilters($field, $row)
 {
     //        ErrorLog("GTF($field,$row)");
     if ($row == NULL) {
         return NULL;
     }
     $searchModule = is_array($row) && array_key_exists('__module__', $row) ? $row['__module__'] : get_class($this);
     $children = isset(self::$targetChildren[$searchModule]) ? self::$targetChildren[$searchModule] : utopia::GetChildren($searchModule);
     $info = NULL;
     // get specific field
     foreach ($children as $links) {
         foreach ($links as $link) {
             if (!isset($link['parentField'])) {
                 continue;
             }
             if ($link['parentField'] == $field) {
                 $info = $link;
                 break;
             }
         }
     }
     // if not found, check for fallback
     if (!$info) {
         if ($field !== '*') {
             return $this->GetTargetFilters('*', $row);
         }
         return NULL;
     }
     //echo "<br/>$field:";
     // fieldLinks: array: parentField => childField
     // need to replace the values
     $targetModule = $info['child'];
     $newFilter = array();
     //		$additional = array();
     //print_r($info['fieldLinks']);
     foreach ($info['fieldLinks'] as $linkInfo) {
         $value = NULL;
         // fromfield == mortgage_id
         // module_pk == VAL:note_id
         if (!$this->FieldExists($linkInfo['fromField']) and $fltr =& $this->FindFilter($linkInfo['fromField'])) {
             // no field exists, but we do have a filter, we should move that over
             $value = $this->GetFilterValue($fltr['uid']);
             // if its a union AND the fromfield equals the modules primarykey then show the module_pk
             // NO,  if its a union, loop thru that modules fields to find the number of the fromField. then get the value of the corresponding number in this union parent module
         } elseif (array_key_exists('__module__', $row)) {
             $obj = utopia::GetInstance($row['__module__']);
             $unionFields = $obj->fields;
             $uFieldCount = 0;
             $keys = array_keys($unionFields);
             foreach ($keys as $uFieldAlias) {
                 if ($uFieldAlias == $linkInfo['fromField']) {
                     break;
                 }
                 $uFieldCount++;
             }
             $ourKeys = array_keys($this->fields);
             $correspondingKey = $ourKeys[$uFieldCount];
             $value = $row[$correspondingKey];
         } else {
             $value = $row[$linkInfo['fromField']];
             // use actual value, getting the real value on every field causes a lot of lookups, the requested field must be the field that stores the actual value
         }
         //echo $value."<br/>";
         if ($value !== NULL) {
             $obj = utopia::GetInstance($targetModule);
             $fltr = $obj->FindFilter($linkInfo['toField']);
             if ($fltr) {
                 $newFilter['_f_' . $fltr['uid']] = $value;
             }
         }
     }
     return $newFilter;
     //print_r(array_merge($newFilter,$additional));
     return array_merge($newFilter, $additional);
     // now returns an array
     $extra = array();
     if (is_array($additional)) {
         foreach ($additional as $key => $val) {
             $extra[] = "{$key}={$val}";
         }
     }
     array_unshift($extra, FilterArrayToString($newFilter));
     return join('&amp;', $extra);
 }
Exemplo n.º 27
0
 public static function getValues()
 {
     if (!isset($_GET['source'])) {
         die('[]');
     }
     $term = isset($_GET['term']) ? $_GET['term'] : '';
     $tmp = cbase64_decode($_GET['source']);
     if (strpos($tmp, ':') === FALSE) {
         return '';
     }
     list($module, $field) = explode(':', $tmp);
     $obj = utopia::GetInstance($module);
     $vals = $obj->GetValues($field);
     $found = array();
     if (is_array($vals)) {
         foreach ($vals as $key => $value) {
             if ($term && !(stripos($key, $term) || stripos($value, $term))) {
                 continue;
             }
             $f = array('key' => $key, 'value' => $value);
             $found[] = $f;
         }
     }
     echo json_encode($found);
 }