Esempio n. 1
0
function spy($x)
{
    switch (1) {
        case is_string($x):
            return '"' . $x . '"';
        case is_numeric($x):
            return $x;
        case is_null($x):
            return 'NULL';
        case is_bool($x):
            return $x ? 'TRUE' : 'FALSE';
        case is_resource($x):
            return '(' . get_resource_type($x) . ')' . "{$x}";
        case is_object($x):
            return get_class($x);
        case is_array($x):
            break;
        case is_scalar($x):
        default:
            return "{$x}";
    }
    switch (count($x)) {
        case 0:
            return '[]';
        case 1:
            return '[' . spy(array_first_key($x)) . ' => ' . spy(array_pop($x)) . ']';
        case 2:
            return '[' . spy(array_first_key($x)) . ' => ' . spy(array_shift($x)) . ', ' . spy(array_last_key($x)) . ' => ' . spy(array_pop($x)) . ']';
        default:
            return '[' . spy(array_first_key($x)) . ' => ' . spy(array_shift($x)) . ', ..., ' . spy(array_last_key($x)) . ' => ' . spy(array_pop($x)) . ']';
    }
    trigger_error('Something terrible has happened.');
}
Esempio n. 2
0
 public function where($name, $value = NULL, $operator = 'AND')
 {
     if (func_num_args() > 3 && in_array(func_num_args() % 3, array(0, 2))) {
         $args = array();
         foreach (func_get_args() as $i => $arg) {
             if ($i % 3 == 0) {
                 $args[] = array($arg);
             } else {
                 $args[array_last_key($args)][] = $arg;
             }
         }
         $this->_request['where'] .= '(';
         foreach ($args as $arg) {
             call_user_func_array(array($this, 'where'), $arg);
         }
         $this->_request['where'] = trim_word($this->_request['where'], ' AND ', ' OR ') . ') AND ';
         return $this;
     }
     if (is_array($value)) {
         $where = $name . ' IN (' . trim_word(implode(', ', array_map(array($this->_driver, 'escape_string'), $value)), ', ') . ') ' . $operator . ' ';
         if (isset($this->_request['where'])) {
             $this->_request['where'] .= $where;
         } else {
             $this->_request['where'] = $where;
         }
         return $this;
     } else {
         $where = $name;
         if (func_num_args() > 1) {
             if (preg_match('/^(.+?) FIND_IN_SET$/', $name, $match)) {
                 $where = 'FIND_IN_SET(' . $this->_driver->escape_string($value) . ', ' . $match[1] . ')';
             } else {
                 if ($value === NULL) {
                     $where .= ' IS ';
                 } else {
                     if (preg_match('/^(.+?) (!=|<>|<|>|<=|>=|=|LIKE)?$/', $name)) {
                         $where .= ' ';
                     } else {
                         $where .= ' = ';
                     }
                 }
                 $where .= $this->_driver->escape_string($value);
             }
         }
         $where .= ' ' . $operator . ' ';
         if (isset($this->_request['where'])) {
             $this->_request['where'] .= $where;
         } else {
             $this->_request['where'] = $where;
         }
         return $this;
     }
 }
Esempio n. 3
0
 function view2($is_form = true)
 {
     global $doc, $form, $list_details;
     $html = '';
     // Передача данных на экспорт в Excel;
     if ($this->export and isset($_POST['exports'])) {
         $_SESSION['export']['name'] = $_POST['exports'];
         $_SESSION['export']['fields'] = $this->fields;
         $_SESSION['export']['data'] = $this->data;
     }
     // Передача данных на экспорт в 1C;
     if ($this->export_xml and isset($_POST['exports_xml'])) {
         $_SESSION['export']['name'] = $this->export_xml['name'];
         $_SESSION['export']['type'] = $this->export_xml['type'];
         $_SESSION['export']['data'] = $this->export_xml['data'];
         $_SESSION['export']['comments'] = $this->export_xml['comments'];
     }
     // Настройки списка;
     if ($this->status) {
         $this->status = $_SESSION['status'][$doc['id']];
     }
     if ($this->action) {
         $this->action = $_SESSION['action'][$doc['id']];
     }
     // Вывод полей;
     if ($this->fields) {
         // Вывод меню;
         if (($this->menu_group_add or $this->menu_add) and $this->access == 2) {
             $html .= '<div class="menu">';
             if ($this->menu_group_add) {
                 $html .= ($this->is_add and $doc['form_group']) ? '<span class="item">Добавить группу</span>' : '<a href="' . $doc['url'] . 'group_add/" class="item">Добавить группу</a>';
             }
             if ($this->menu_add) {
                 $html .= ($this->is_add and !$doc['form_group']) ? '<span class="item">Добавить</span>' : '<a href="' . $doc['url'] . 'add/" class="item">Добавить</a>';
             }
             $html .= '</div>';
         }
         $html .= '<div class="caption">';
         $html .= '<table cellpadding="0" cellspacing="0" border="0" class="list">';
         $html .= '<tr>';
         foreach ($this->fields as $col => $item) {
             $html .= '<th class="' . $item['type'] . '">';
             $html .= '<div class="field">';
             $html .= $item['title'];
             // Сортировка;
             if ($this->is_order and $item['order'] !== false) {
                 $html .= ' <div class="order' . (isset($_SESSION['order'][$doc['id']][$item['name']]) ? ' ' . strtolower($_SESSION['order'][$doc['id']][$item['name']]) : '') . '" onclick="set_order(\'' . $item['name'] . '\');"></div>';
             }
             // Фильтр;
             if ($this->is_filter and is_array($item['filter'])) {
                 $html .= '<div class="filter"><div' . (isset($_SESSION['filter'][$doc['id']][$item['name']]) ? ' class="set"' : '') . '></div></div>';
                 $html .= '<div class="filter-form">';
                 if (isset($item['filter']['items'])) {
                     if ($item['filter']['type'] == 'input') {
                         $html .= '--input--';
                     }
                     if ($item['filter']['type'] == 'select') {
                         $html .= '<select onchange="set_filter(\'' . $doc['id'] . '\', \'' . $item['filter']['type'] . '\', \'' . $item['name'] . '\', $(this).val());">';
                         $html .= '<option value="">--</option>';
                         foreach ($item['filter']['items'] as $k => $v) {
                             $html .= '<option value="' . $k . '"' . (isset($_SESSION['filter'][$doc['id']][$item['name']]) ? $_SESSION['filter'][$doc['id']][$item['name']]['value'] == $k ? ' selected' : '' : '') . '>' . $v . '</option>';
                         }
                         $html .= '</option>';
                     }
                     if ($item['filter']['type'] == 'check') {
                         foreach ($item['filter']['items'] as $k => $v) {
                             $html .= '<div><input id="filter-' . $col . '-' . $k . '" type="checkbox" class="check"' . (isset($_SESSION['filter'][$doc['id']][$item['name']]['value'][$k]) ? ' checked' : '') . ' onclick="set_filter(\'' . $doc['id'] . '\', \'' . $item['filter']['type'] . '\', \'' . $item['name'] . '\', \'' . $k . '\');" /> <label for="filter-' . $item['name'] . '-' . $k . '">' . $v . '</label></div>';
                         }
                     }
                 }
                 $html .= '</div>';
             }
             $html .= '</div>';
             $html .= '</th>';
         }
         $html .= '</tr>';
         $html .= '</table>';
         $html .= '</div>';
         // Вывод данных;
         if ($this->data) {
             $html .= '<div class="data' . ($this->class ? ' ' . $this->class : '') . '">';
             foreach ($this->data as $key => $value) {
                 if ($is_form) {
                     $html .= '<a href="' . ($is_form !== true ? $is_form : $doc['url']) . (isset($value['group']) ? 'group' : '') . $value['id'] . '/" class="item' . (isset($value['group']) ? ' group' : (isset($value['group_id']) ? ' group-' . $value['group_id'] : '')) . (isset($value['hidden']) ? ' hidden' : '') . '"' . (isset($value['group']) ? ' group="' . $value['id'] . '"' : '') . '>';
                 }
                 $html .= '<table cellpadding="0" cellspacing="0" border="0" class="list' . (isset($value['color']) ? ' color-' . $value['color'] : '') . '">';
                 $html .= '<tr' . (isset($value['id']) ? ' id="item-' . $value['id'] . '"' : '') . ' class="item' . ((isset($doc['form_view']) and isset($value['id']) and $value['id'] == $doc['form_view']) ? ' open' : '') . ($key % 2 == 0 ? '' : ' parity') . (($key == array_last_key($this->data) and count($this->data) > ($this->class == 'min' ? 5 : 9)) ? ' last' : '') . '">';
                 if (isset($value['group'])) {
                     // Вывод данных;
                     $html .= '<td class="' . (isset($value['level']) ? 'level-' . $value['level'] : '') . '" colspan="' . count($this->fields) . '">' . str_pad('', $value['level'] - 1, '-', STR_PAD_LEFT) . ' ' . $value['name'] . '</td>';
                 } else {
                     foreach ($this->fields as $col => $item) {
                         // Обработка типизированных данных;
                         if ($item['type'] == 'code menu') {
                             $value[$item['name']] = $this->code_menu($value[$item['name']]);
                         }
                         if ($item['type'] == 'date') {
                             $value[$item['name']] = $value[$item['name']] ? date("d.m.Y", strtotime($value[$item['name']])) : '';
                         }
                         if ($item['type'] == 'time') {
                             $value[$item['name']] = date("H:i", strtotime($value[$item['name']]));
                         }
                         if ($item['type'] == 'time min') {
                             $value[$item['name']] = date("i:s", strtotime($value[$item['name']]));
                         }
                         if ($item['type'] == 'datetime') {
                             $value[$item['name']] = $value[$item['name']] ? date("d.m.Y, H:i", strtotime($value[$item['name']])) : '';
                         }
                         if ($item['type'] == 'period') {
                             $value[$item['name']] = explode(":", $value[$item['name']]);
                             $value[$item['name']] = 'с ' . date("d.m.Y", strtotime($value[$item['name']][0])) . ' по ' . date("d.m.Y", strtotime($value[$item['name']][1]));
                         }
                         if ($item['type'] == 'money' or $item['type'] == 'money min' or $item['type'] == 'money nano') {
                             $value[$item['name']] = isset($value[$item['name']]) ? number_format($value[$item['name']], 2, '.', ' ') : '0.00';
                         }
                         if ($item['type'] == 'count' or $item['type'] == 'count min' or $item['type'] == 'count nano') {
                             $value[$item['name']] = $value[$item['name']] ? number_format($value[$item['name']], 0, '.', ' ') : '0';
                         }
                         if ($item['type'] == 'count color') {
                             if (isset($value['count_max'])) {
                                 if ($value[$item['name']] >= $value['count_max']) {
                                     $item['type'] = 'count red';
                                 }
                             }
                             $value[$item['name']] = $value[$item['name']] ? number_format($value[$item['name']], 0, '.', ' ') : '0';
                         }
                         if ($item['type'] == 'list') {
                             $value[$item['name']] = isset($item['data'][$value[$item['name']]]) ? $item['data'][$value[$item['name']]] : $value[$item['name']];
                         }
                         if ($item['type'] == 'list min' or $item['type'] == 'list mid' or $item['type'] == 'list max') {
                             $value[$item['name']] = isset($item['data'][$value[$item['name']]]) ? $item['data'][$value[$item['name']]] : $value[$item['name']];
                         }
                         if ($item['type'] == 'phone') {
                             $value[$item['name']] = isset($this->permissions['phone']) ? '<a href="/" onclick="return client_call(\'' . $value['client_id'] . '\', \'' . str_replace("+7", "8", $value[$item['name']]) . '\');">' . $value[$item['name']] . '</a>' : $value[$item['name']];
                         }
                         if ($item['type'] == 'photo') {
                             $value[$item['name']] = $value[$item['name']] ? '<img src="/systems/image.php?clients=' . $value[$item['name']] . '" src="" />' : '';
                         }
                         if ($item['type'] == 'photo min') {
                             $value[$item['name']] = $value[$item['name']] ? '+' : '';
                         }
                         //if ($item['type'] == 'position') $value[$item['name']] = (($key > 0) ? '<span onclick="set_position(\''.$value['id'].'\', -3);">&#9650;</span>' :'').(($key < array_last_key($this->data)) ? '<span onclick="set_position(\''.$value['id'].'\', 3);">&#9660;</span>' : '');
                         if ($item['type'] == 'status') {
                             $value[$item['name']] = $value[$item['name']] == 1 ? 'Да' : 'Нет';
                         }
                         // Вывод данных;
                         $html .= '<td class="' . $item['type'] . ($col == array_last_key($this->fields) ? ' last' : '') . '"' . (isset($item['style']) ? ' style="' . $item['style'] . '"' : '') . '>' . (isset($value[$item['name']]) ? $value[$item['name']] : '') . '</td>';
                     }
                 }
                 $html .= '</tr>';
                 $html .= '</table>';
                 if ($is_form) {
                     $html .= '</a>';
                 }
                 // Ограничение списка;
                 if ($this->limit and $key == 998) {
                     $html .= '<table cellpadding="0" cellspacing="0" border="0" class="list">';
                     $html .= '<tr class="parity">';
                     $html .= '<td class="last-row">Воспользуйтесь поиском</td>';
                     $html .= '</tr>';
                     $html .= '</table>';
                     break;
                 }
                 unset($this->data[$key]);
             }
             $html .= '</div>';
         } else {
             $html .= '<div class="data">';
             $html .= '<div class="no">нет данных</div>';
             $html .= '</div>';
         }
         if ($this->sum or $this->info) {
             $html .= '<div class="data-sum">';
             $html .= '<table cellpadding="0" cellspacing="0" border="0">';
             $html .= '<tr>';
             $col_first = true;
             foreach ($this->fields as $col => $item) {
                 if (isset($this->sum[$col])) {
                     $html .= '<td class="' . $item['type'] . ' value"><div class="value">' . number_format($this->sum[$col], 2, '.', ' ') . '</div></td>';
                     $col_first = true;
                 } elseif (isset($this->info[$col])) {
                     $html .= '<td class="' . $item['type'] . ' value">' . $this->info[$col] . '</td>';
                     $col_first = true;
                 } else {
                     $html .= '<td class="' . $item['type'] . ($col_first ? ' first' : '') . '">&nbsp;</td>';
                     $col_first = false;
                 }
             }
             $html .= '<td style="width: 17px; padding: 0px;"></td>';
             $html .= '</tr>';
             $html .= '</table>';
             $html .= '</div>';
         }
         if ($this->status) {
             $html .= '<div class="data-status">';
             $html .= '<span><input id="status-1" type="checkbox"' . (isset($this->status[1]) ? ' checked' : '') . ' class="check" onclick="if (set_status(1)) $(\'#search\').submit();" /> <label for="status-1">Активные</label></span>';
             $html .= '<span><input id="status-0" type="checkbox"' . (isset($this->status[0]) ? ' checked' : '') . ' class="check" onclick="if (set_status(0)) $(\'#search\').submit();" /> <label for="status-0">Неактивные</label></span>';
             $html .= '</div>';
         }
         if ($this->action) {
             $html .= '<div class="data-action">';
             $html .= '<span><input id="action-money" type="checkbox"' . (isset($this->action['money']) ? ' checked' : '') . ' class="check" onclick="if (set_action(\'money\')) $(\'#search\').submit();" /> <label for="action-money">Оплаченные</label></span>';
             $html .= '<span><input id="action-2" type="checkbox"' . (isset($this->action[2]) ? ' checked' : '') . ' class="check" onclick="if (set_action(2)) $(\'#search\').submit();" /> <label for="action-2">Подключенные</label></span>';
             $html .= '<span><input id="action-1" type="checkbox"' . (isset($this->action[1]) ? ' checked' : '') . ' class="check" onclick="if (set_action(1)) $(\'#search\').submit();" /> <label for="action-1">Неподключенные</label></span>';
             $html .= '</div>';
         }
         $html .= '<div class="data-count">';
         if ($this->count) {
             // Количество записей;
             if ($this->count === true) {
                 $this->count = count($this->data);
             }
             $html .= '<div>Количество записей: ' . number_format($this->count, 0, '.', ' ') . '</div>';
         }
         $html .= '</div>';
         if ($this->print or $this->export or $this->export_xml) {
             $html .= '<div class="data-events">';
             if (isset($this->permissions['print'])) {
                 $html .= '<div class="button" onclick="content_print();"><div>Печать</div></div>';
             }
             if (isset($this->permissions['export'])) {
                 if ($this->export) {
                     $html .= '<div class="button" onclick="content_export(\'' . $doc['url'] . (isset($doc['form_view']) ? $doc['form_view'] . '/' : '') . '\', \'' . $doc['name'] . '\');"><div>Экспорт в Excel</div></div>';
                 }
                 if ($this->export_xml) {
                     $html .= '<div class="button" onclick="content_export_xml(\'' . $doc['url'] . (isset($doc['form_view']) ? $doc['form_view'] . '/' : '') . '\', \'' . $doc['name'] . '\', \'' . $this->export_xml['type'] . '\');"><div>Экспорт в 1C</div></div>';
                 }
             }
             $html .= '<div class="clear"></div>';
             $html .= '</div>';
         }
     }
     echo $html;
 }
Esempio n. 4
0
 public function widget_add($disposition_id, $disposition, $row_id, $col_id, $title, $widget_name, $type, $settings)
 {
     $widget_id = $this->db->insert('nf_widgets', array('title' => $title ? utf8_htmlentities($title) : NULL, 'widget' => $widget_name, 'type' => $type, 'settings' => $this->load->widget($widget_name)->get_settings($type, $settings)));
     $widget = $disposition[$row_id]->cols[$col_id]->widgets[] = new Widget_View(array('widget_id' => $widget_id));
     $this->model()->set_disposition($disposition_id, $disposition);
     return $widget->display(array_last_key($disposition[$row_id]->cols[$col_id]->widgets));
 }