示例#1
0
 public static function record_bbcode($tab, $fields, $text, $param, $opt)
 {
     if (!is_numeric($param)) {
         $parts = explode(' ', $text);
         $crits = array();
         foreach ($parts as $k => $v) {
             $v = "%{$v}%";
             $chr = '(';
             foreach ($fields as $f) {
                 $crits[$chr . str_repeat('_', $k) . $f] = $v;
                 $chr = '|';
             }
         }
         $rec = Utils_RecordBrowserCommon::get_records($tab, $crits, array(), array(), 1);
         if (is_array($rec) && !empty($rec)) {
             $rec = array_shift($rec);
         } else {
             $crits = array();
             foreach ($parts as $k => $v) {
                 $v = "%{$v}%";
                 $chr = '(';
                 foreach ($fields as $f) {
                     $crits[$chr . str_repeat('_', $k) . '~' . $f] = $v;
                     $chr = '|';
                 }
             }
             $rec = Utils_RecordBrowserCommon::get_records($tab, $crits, array(), array(), 1);
             if (is_array($rec)) {
                 $rec = array_shift($rec);
             } else {
                 $rec = null;
             }
         }
     } else {
         $rec = Utils_RecordBrowserCommon::get_record($tab, $param);
     }
     if ($opt) {
         if (!$rec) {
             return null;
         }
         return Utils_BBCodeCommon::create_bbcode(null, $rec['id'], $text);
     }
     if ($rec) {
         return Utils_RecordBrowserCommon::record_link_open_tag_r($tab, $rec) . $text . Utils_RecordBrowserCommon::record_link_close_tag();
     }
     return Utils_BBCodeCommon::create_bbcode(null, $param, $text, __('Record not found'));
 }