Example #1
0
 /**
  * Displays a form for updating a role name and a table of available permissions that
  * can be checked to add to the role.
  */
 public static function edit($id)
 {
     $role = User::role()->find($id);
     if (isset($_POST['update_role'])) {
         if ($_POST['name'] == $role->name || !User::role()->where('name', 'LIKE', $_POST['name'])->first()) {
             $status = User::role()->where('id', '=', $id)->update(array('name' => $_POST['name']));
             if ($status) {
                 Message::ok('Role updated successfully.');
                 $role->name = $_POST['name'];
                 // Set updated name for form
             } else {
                 Message::info('Nothing changed.');
             }
         } else {
             Message::error('A role with that name is already in use.');
         }
     }
     if (isset($_POST['update_perms'])) {
         User::permission()->where('role_id', '=', $role->id)->delete();
         if (isset($_POST['permissions'])) {
             foreach ($_POST['permissions'] as $permission) {
                 User::permission()->insert(array('role_id' => $id, 'permission' => $permission));
             }
         }
         Message::ok('Permissions updated successfully.');
     }
     $fields[] = array('fields' => array('name' => array('title' => 'Name', 'type' => 'text', 'default_value' => $role->name, 'validate' => array('required')), 'update_role' => array('value' => 'Update Role', 'type' => 'submit')));
     $formHtml = Html::form()->build($fields);
     $table = Html::table();
     $table->addHeader()->addCol('Module Roles', array('colspan' => 2));
     $sortedPermissions = User::getSortedPermissions();
     $setPermissions = User::permission()->where('role_id', '=', $id)->all();
     $tmp = array();
     foreach ($setPermissions as $ap) {
         $tmp[] = $ap->permission;
     }
     $setPermissions = $tmp;
     foreach ($sortedPermissions as $module => $modulePermissions) {
         $nameRow = $table->addRow();
         $nameRow->addCol(sprintf('<strong>%s</strong>', ucfirst($module)), array('colspan' => 2));
         foreach ($modulePermissions as $permission => $desc) {
             $fieldRow = $table->addRow();
             $checked = in_array($permission, $setPermissions) ? ' checked="checked"' : '';
             $fieldRow->addCol('<input type="checkbox" name="permissions[]" value="' . $permission . '"' . $checked . ' />', array('width' => 10));
             $fieldRow->addCol($desc);
         }
     }
     // TODO This is a bit hacky, figure a better way to make tables into forms
     $tableHtml = Html::form()->open(null, 'post', false, array('name' => 'perms', 'id' => 'perms'));
     $tableHtml .= $table->render();
     $tableHtml .= '<div class="buttons">';
     $tableHtml .= '<input type="hidden" name="update_perms" value="true" />';
     $tableHtml .= '<a class="blue btn submitter" href="#">Update Permissions</a>';
     $tableHtml .= '</div>';
     $tableHtml .= Html::form()->close();
     return array(array('title' => 'Edit Role', 'content' => $formHtml), array('title' => 'Edit Role Permissions', 'content' => $tableHtml));
 }
Example #2
0
 function display()
 {
     global $CFG;
     if ($this->is_inset && !($CFG->id > 0)) {
         return false;
     }
     $link_prefix = $CFG->backstage_mode ? 'index.php?is_tab=1&current_url=' : '';
     $HTML = "\n\t\t<div class=\"area full_box inset_tabs\">  \n\t\t\t<h2>{$legend}</h2>\n\t\t\t<div class=\"box_bar\"></div>\n\t\t\t<div class=\"box_tl\"></div>\n\t\t\t<div class=\"box_tr\"></div>\n\t\t\t<div class=\"box_bl\"></div>\n\t\t\t<div class=\"box_br\"></div>\n\t\t\t<div class=\"t_shadow\"></div>\n\t\t\t<div class=\"r_shadow\"></div>\n\t\t\t<div class=\"b_shadow\"></div>\n\t\t\t<div class=\"l_shadow\"></div>\n\t\t\t<div class=\"box_b\"></div>\n\t\t\t<div class=\"a_tabs\">";
     if (is_array($this->tabs)) {
         foreach ($this->tabs as $name => $properties) {
             if (User::permission(0, 0, $properties['url'], false, $properties['is_tab']) > 0) {
                 $key = $properties['order'];
                 $link_prefix1 = $CFG->backstage_mode ? 'index.php?inset_id=' . $CFG->id . '&inset_id_field=' . $properties['inset_id_field'] . '&inset_url=' . $properties['url'] . '&is_tab=' . $properties['is_tab'] . '&inset_i=' . $this->i . '&current_url=' : '';
                 $selected = !is_array($first_tab) || $properties['selected'] ? 'visible' : '';
                 $first_tab = !is_array($first_tab) || $properties['selected'] ? $properties : $first_tab;
                 $query_string = Link::parseVariables($properties['variables']);
                 $query_string = $query_string ? '?' . $query_string : '';
                 $identifier = !empty($properties['identifier']) ? $properties['identifier'] : "tabs_{$this->i}_blank";
                 $tab_identifier = $this->is_navigation ? (!strstr($properties['url'], '?') ? '?' : '&') . 'tab_identifier=' . $key : '';
                 $onclick = !empty($properties['url']) ? ' onclick="tabsSelectTab(\'' . $link_prefix1 . $properties['url'] . $query_string . $tab_identifier . '\',\'' . $this->target_elem . '\',this)" ' : '';
                 $pm_method = $CFG->pm_editor ? 'pm_method' : '';
                 //$del_id = ($this->is_navigation) ? "id=\"del_tab_$key\"" : '';
                 if ($CFG->pm_editor) {
                     $method_name = Form::peLabel($properties['method_id'], 'makeTab');
                 }
                 $HTML_ARR[$key] = '<a class="a_tab ' . $selected . ' ' . $pm_method . '" ' . $onclick . ' id="' . $identifier . '"><div class="contain1">' . $name . '</div><div class="l"></div><div class="r"></div><div class="c"></div></a>' . $method_name;
             }
         }
     }
     ksort($HTML_ARR);
     $HTML .= implode($HTML_ARR);
     $HTML .= '</div><div class="contain">';
     echo $HTML;
     if ($this->is_inset) {
         $CFG->inset_id = $CFG->id;
         $CFG->inset_id_field = $first_tab['inset_id_field'];
         $CFG->inset_target_elem = $this->target_elem;
         $CFG->inset_is_tab = $first_tab['is_tab'];
         $CFG->inset_url = $first_tab['url'];
         $CFG->inset_i = $this->i;
         echo '<div class="inset_area" id="inset_area_' . $this->i . '">';
         if (is_array($this->tabs)) {
             $control = new Control($first_tab['url'], false, $first_tab['is_tab']);
         }
         echo '</div>';
     }
     echo '</div></div>';
 }
Example #3
0
 function link($url = false, $caption = false, $variables = false, $target_elem_id = false, $class = false, $disable_if_no_record_id = false, $disable_if_cant_edit = false)
 {
     global $CFG;
     $variables1 = String::parseVariables($variables, $this->info, $this->record_id, $url);
     $variables1['bypass_save'] = 1;
     $permission_level = $variables1['action'] == 'form' ? 2 : 1;
     $disabled = User::permission(0, 0, $url, false, $variables1['is_tab']) <= $permission_level;
     $disabled = !($this->record_id > 0) && $disable_if_no_record_id ? true : $disabled;
     $target_elem_id = !$target_elem_id ? 'content' : $target_elem_id;
     $class = $class ? $class : 'nav_link';
     if ($CFG->pm_editor) {
         $method_name = self::peLabel($CFG->method_id, 'link');
     }
     $this->HTML[] = Link::url($url, $caption, false, $variables1, false, $target_elem_id, $class, false, false, false, $disabled) . $method_name;
 }
Example #4
0
 function link($url = false, $caption = false, $variables = false, $target_elem_id = false, $class = false, $disable_if_no_record_id = false, $disable_if_cant_edit = false)
 {
     global $CFG;
     $reserved_keywords = array('current_url', 'action', 'bypass', 'is_tab');
     if (is_array($variables)) {
         foreach ($variables as $k => $v) {
             $v1 = str_replace('[', '', str_replace(']', '', $v));
             if (in_array($k, $reserved_keywords)) {
                 $variables1[$k] = $v;
             } elseif ($k == 'id') {
                 $variables1[$k] = $this->record_id;
             } elseif ($v1 == 'id') {
                 $variables1["{$url}[{$k}]"] = $this->record_id;
             } else {
                 $variables1["{$url}[{$k}]"] = $this->row[$v1];
             }
         }
     }
     $variables1['bypass_save'] = 1;
     $permission_level = $variables1['action'] == 'form' ? 2 : 1;
     $disabled = User::permission(0, 0, $url, false, $variables1['is_tab']) < $permission_level;
     $disabled = !($this->record_id > 0) && $disable_if_no_record_id ? true : $disabled;
     $target_elem_id = !$target_elem_id ? 'content' : $target_elem_id;
     $class = $class ? $class : 'nav_link';
     if ($CFG->pm_editor) {
         $method_name = Form::peLabel($CFG->method_id, 'link');
     }
     $this->HTML[] = Link::url($url, '<div class="add_new"></div> ' . $caption, false, $variables1, false, $target_elem_id, $class, false, false, false, $disabled) . $method_name;
 }
Example #5
0
    function display($page = 0)
    {
        global $CFG;
        $filters = self::getFilterResults();
        $page = $page > 0 ? $page : $_SESSION['page' . $this->i];
        $_SESSION['page' . $this->i] = $page;
        $page = !($page > 0) || $_REQUEST['submit'] || $this->order_asc_changed || $this->order_by_changed ? 1 : $page;
        $fields = DB::getTableFields($this->table);
        $total_rows = DB::get($this->table, $this->fields, $page, $this->rows_per_page, $this->order_by, $this->order_asc, 1, $filters, $this->inset_id, $this->inset_id_field, false, false, false, false, false, false, false, $this->sql_filter, $this->group_by, $this->no_group_by);
        $data = DB::get($this->table, $this->fields, $page, $this->rows_per_page, $this->order_by, $this->order_asc, 0, $filters, $this->inset_id, $this->inset_id_field, false, false, false, false, false, false, false, $this->sql_filter, $this->group_by, $this->no_group_by);
        $HTML = "";
        if ($CFG->backstage_mode && User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1 && $this->inset_id === false) {
            $HTML .= '
			<form id="grid_form_' . $this->table . $this->i . '" name="grid_form_' . $this->table . $this->i . '" action="' . $CFG->self . '" method="POST">
				<input type="hidden" name="current_url" value="' . $CFG->url . '" />
				<input type="hidden" name="action" value="" />
				<input type="hidden" name="return_to_self" value="1" />';
            if (is_array($this->fields)) {
                foreach ($this->fields as $properties) {
                    if ($properties['aggregate_function']) {
                        $i_name = $properties['name'];
                        switch ($properties['aggregate_function']) {
                            case 'grand_total':
                                $grand_total[$i_name] = 0;
                                break;
                            case 'page_total':
                                $page_total[$i_name] = 0;
                                break;
                            case 'grand_avg':
                                $grand_avg[$i_name] = array();
                                break;
                            case 'page_avg':
                                $page_avg[$i_name] = array();
                                break;
                            case 'both_total':
                                $page_total[$i_name] = 0;
                                $grand_total[$i_name] = 0;
                                break;
                            case 'both_avg':
                                $page_avg[$i_name] = array();
                                $grand_avg[$i_name] = array();
                                break;
                        }
                    }
                }
            }
            if (is_array($this->fields)) {
                foreach ($this->fields as $properties) {
                    if ($properties['cumulative_function']) {
                        $i_name = $properties['name'];
                        if ($properties['cumulative_function'] == 'sum') {
                            $page_total[$i_name] = 0;
                            if ($grand_total) {
                                $grand_total[$i_name] = 0;
                            }
                        } elseif ($properties['cumulative_function'] == 'avg') {
                            $page_avg[$i_name] = array();
                            if ($grand_avg) {
                                $grand_avg[$i_name] = array();
                            }
                        }
                    }
                }
            }
        }
        if ($this->mode == 'list') {
            $HTML .= "<ul class=\"grid_list\">";
            if (is_array($data)) {
                $j = 0;
                foreach ($data as $row) {
                    $HTML .= "<li><ul>";
                    if (is_array($this->fields)) {
                        foreach ($this->fields as $name => $properties) {
                            $key = $name;
                            if (strstr($name, 'lll')) {
                                $name_parts = explode('lll', $name);
                                $name = $name_parts[0];
                            }
                            if ($this->inset_id > 0 && $name == $this->inset_id_field) {
                                continue;
                            }
                            $value = $row[$key];
                            $link_id = $row[$name . '_id'] ? $row[$name . '_id'] : $value;
                            $class = $properties['class'] ? "class=\"{$properties['class']}\"" : '';
                            if ($CFG->pm_editor) {
                                $method_name = Form::peLabel($properties['method_id'], 'field');
                            }
                            $HTML .= "<li {$class}>" . $method_name . "";
                            if (!empty($properties['is_media'])) {
                                reset($CFG->image_sizes);
                                $m_values = explode('|||', $value);
                                $m_size = !empty($properties['media_size']) ? $properties['media_size'] : key($CFG->image_sizes);
                                $m_limit = !empty($properties['media_amount']) ? $properties['media_amount'] : 1;
                                $HTML .= Gallery::multiple($properties['subtable'], $row['id'], $properties['name'], $properties['media_size'], 0, false, $properties['media_amount'], false, false, true);
                                $HTML .= '<div class="clear"></div>';
                            } else {
                                if ($fields[$name]['Type'] == 'datetime' || @in_array($name, $foreign_dates)) {
                                    $value = date($CFG->default_date_format, strtotime($value));
                                } elseif ($fields[$name]['Type'] == "enum('Y','N')") {
                                    $value = $value == 'Y' ? '<div class="y_icon"></div>' : '<div class="n_icon"></div>';
                                }
                                if ($value['filter']) {
                                    $order_asc = $this->order_asc ? false : true;
                                    if ($this->order_by == $name) {
                                        $dir_img = $this->order_asc ? $CFG->up : $CFG->down;
                                    } else {
                                        $dir_img = false;
                                    }
                                    $HTML .= '<b>' . Link::url($this->link_url, $properties['header_caption'] . $dir_img, "filter{$this->i}={$name}&order_by{$this->i}={$this->order_by}&order_asc{$this->i}={$order_asc}&is_tab={$this->is_tab}", $this->filter_results, false, 'content') . ':</b> ';
                                } else {
                                    $HTML .= $this->show_list_captions ? '<b>' . $properties['header_caption'] . ':</b> ' : '';
                                }
                                if (empty($properties['link_url'])) {
                                    $HTML .= str_ireplace('|||', ' ', $value);
                                } else {
                                    $action = $CFG->backstage_mode ? '&action=record' : '';
                                    $value = str_replace('|||', ' ', $value);
                                    if (!empty($value)) {
                                        $HTML .= Link::url($properties['link_url'], $value, "id={$link_id}&is_tab={$properties['link_is_tab']}{$action}", false, false, $this->target_elem_id);
                                    }
                                }
                                if (is_array($page_total)) {
                                    if (array_key_exists($name, $page_total)) {
                                        $page_total[$name] += $value;
                                    }
                                }
                                if (is_array($page_avg)) {
                                    if (array_key_exists($name, $page_avg)) {
                                        $page_avg[$name][] = $value;
                                    }
                                }
                            }
                            $HTML .= "</li>";
                        }
                    }
                    if ($this->show_buttons) {
                        $HTML .= '<li><nobr>' . ($CFG->backstage_mode ? "<span><label for=\"{$row['id']}\">Select:</label><input id=\"{$row['id']}\" type=\"checkbox\" value=\"{$row['id']}\" class=\"grid_select checkbox_input\"/></span>" : '');
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 0) {
                            $HTML .= Link::url($this->link_url, false, 'id=' . $row['id'] . '&action=record&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1) {
                            $HTML .= Link::url($this->link_url, false, 'id=' . $row['id'] . '&action=form&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1) {
                            $HTML .= '<a href="#" class="delete" title="' . $CFG->delete_hover_caption . '" onclick="gridDelete(' . $row['id'] . ',\'' . $this->table . '\',this)"></a></li>';
                        }
                    }
                    $HTML .= '</nobr></li></ul>';
                    $j++;
                }
            } else {
                $HTML .= '<li>' . $CFG->grid_no_results . '</li>';
            }
            $HTML .= "</ul>";
        } elseif ($this->mode == 'graph' || $this->mode == 'graph_line' || $this->mode == 'graph_pie') {
            $name_column = $this->graph_name_column;
            $y_axis = $this->graph_value_column;
            $x_axis = $this->graph_x_axis;
            if (is_array($this->fields)) {
                foreach ($this->fields as $name => $properties) {
                    if (strstr($fields[$name]['Type'], 'varchar') || !$properties['is_op'] && !empty($properties['subtable'])) {
                        if (!$name_column) {
                            $name_column = $name;
                        }
                        $this->name_columns[$name] = $properties['header_caption'];
                    } elseif (strstr($fields[$name]['Type'], 'date')) {
                        if (!$x_axis) {
                            $x_axis = $name;
                        }
                        $this->x_columns[$name] = $properties['header_caption'];
                    } elseif (($properties['is_op'] || strstr($fields[$name]['Type'], 'int') || strstr($fields[$name]['Type'], 'double')) && $name != 'id' && empty($properties['subtable'])) {
                        if (!$y_axis) {
                            $y_axis = $name;
                        }
                        $this->value_columns[$name] = $properties['header_caption'];
                    }
                }
            }
            if ($data) {
                foreach ($data as $row) {
                    $x_values[] = strtotime($row[$x_axis]);
                    $y_values[] = $row[$y_axis];
                }
                $days = (max($x_values) - min($x_values)) / 86400;
                $max_x = max($x_values);
                $min_x = min($x_values);
                $timestamp = $min_x;
                if ($days <= 30) {
                    $time_unit = 'days';
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp += 86400;
                    }
                } elseif ($days > 30 && $days <= 183) {
                    $time_unit = 'weeks';
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp += 86400 * 7;
                    }
                } elseif ($days > 183 && $days <= 910) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 1 month')));
                    }
                } elseif ($days > 910 && $days <= 1820) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 2 months')));
                    }
                } elseif ($days > 1820 && $days <= 3640) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 4 months')));
                    }
                } elseif ($days > 3640 && $days <= 7280) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 6 months')));
                    }
                } elseif ($days > 7280 && $days <= 14560) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 8 months')));
                    }
                } elseif ($days > 14560 && $days <= 29120) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 10 months')));
                    }
                } elseif ($days > 29120 && $days <= 58240) {
                    $time_unit = 'years';
                    $timestamp = strtotime(date('1/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('1/1/Y', strtotime($p_name . ' + 1 year')));
                    }
                }
                $reps = 0;
                foreach ($data as $row) {
                    if (is_array($this->fields)) {
                        $name_value = $this->graph_combine != 'Y' ? $row[$name_column] : 'All';
                        $c_units = count($time_units);
                        $x_val = strtotime($row[$x_axis]);
                        for ($i = 0; $i < $c_units; $i++) {
                            if ($x_val >= $time_units[$i] && ($x_val < $time_units[$i + 1] || !$time_units[$i + 1])) {
                                $x_current = $time_units[$i];
                                break;
                            }
                        }
                        $key = $x_current;
                        if ($x_prev != $x_current) {
                            $y_current = false;
                            $reps = 0;
                        }
                        if ($this->fields[$y_axis]['is_op'] && !$this->fields[$y_axis]['run_in_sql']) {
                            $y_current = self::doOperation($y_axis, $this->fields[$y_axis], $row, $name_value);
                        } else {
                            $y_current = $y_current + $row[$y_axis];
                        }
                        $x_prev = $x_current;
                        if ($this->mode != 'graph_pie') {
                            if (!$graph_data[$name_value][$key]) {
                                $graph_data[$name_value][$key] = $y_current;
                            } else {
                                if ($this->fields[$y_axis]['cumulative_function'] == 'avg') {
                                    $graph_data[$name_value][$key] = ($graph_data[$name_value][$key] + $y_current) / $reps;
                                } else {
                                    $graph_data[$name_value][$key] += $y_current;
                                }
                            }
                        } else {
                            if (!$graph_data[1][$name_value]) {
                                $graph_data[1][$name_value] = $y_current;
                            } else {
                                if ($this->fields[$y_axis]['cumulative_function'] == 'avg') {
                                    $graph_data[1][$name_value] = ($graph_data[1][$name_value] + $y_current) / $reps;
                                } else {
                                    $graph_data[1][$name_value] += $y_current;
                                }
                            }
                        }
                        $titles[$name_value] = $name_value;
                        $reps++;
                    }
                }
                if ($this->mode != 'graph_pie') {
                    foreach ($graph_data as $name_value => $val) {
                        $last_value = 0;
                        foreach ($time_units as $unit) {
                            $key = $unit;
                            if (!array_key_exists($key, $graph_data[$name_value])) {
                                if (!empty($this->fields[$y_axis]['cumulative_function'])) {
                                    $graph_data[$name_value][$key] = $last_value;
                                } else {
                                    $graph_data[$name_value][$key] = 0;
                                }
                            } else {
                                $last_value = $graph_data[$name_value][$key];
                            }
                        }
                    }
                    foreach ($graph_data as $name_value => $val) {
                        ksort($graph_data[$name_value]);
                        $last_value = 0;
                        foreach ($graph_data[$name_value] as $key => $val) {
                            if ($time_unit == 'days' || $time_unit == 'weeks') {
                                $key1 = date('M j', $key);
                            } elseif ($time_unit == 'months') {
                                $key1 = date('M', $key);
                            } elseif ($time_unit == 'years') {
                                $key1 = date('Y', $key);
                            }
                            $graph_data1[$name_value][$key1] = $val;
                        }
                    }
                } else {
                    $graph_data1 = $graph_data;
                }
            }
            $HTML .= '<img class="graph" src="includes/graph.php?graph_data=' . urlencode(serialize($graph_data1)) . '&titles=' . urlencode(serialize($titles)) . '&mode=' . $this->mode . '">';
        } else {
            $HTML .= "<table><tr class=\"grid_header\">";
            if ($CFG->backstage_mode && !$this->links_out && $this->show_buttons && $CFG->is_ctrl_panel != 'Y') {
                $HTML .= "<th><label for=\"grid_select{$this->i}\"/><input id=\"grid_select{$this->i}\" type=\"checkbox\" class=\"grid_select checkbox_input\" onclick=\"gridSelectAll(this)\"/></th>";
            }
            if (is_array($this->fields)) {
                foreach ($this->fields as $name => $value) {
                    $key = $name;
                    if (strstr($name, 'lll')) {
                        $name_parts = explode('lll', $name);
                        $name = $name_parts[0];
                    }
                    if ($this->inset_id > 0) {
                        if ($value['name'] == $this->inset_id_field) {
                            continue;
                        }
                        if (strstr($this->inset_id_field, '.')) {
                            $inset_field_parts = explode('.', $this->inset_id_field);
                            if ($value['subtable'] == $inset_field_parts[0] && (in_array($inset_field_parts[1], $value['subtable_fields']) || $inset_field_parts[1] == 'id')) {
                                continue;
                            }
                        }
                    }
                    if ($value['is_op'] && !$value['run_in_sql']) {
                        if ($CFG->pm_editor) {
                            $method_name = Form::peLabel($value['method_id'], 'aggregate');
                        }
                        $HTML .= "<th>" . $value['header_caption'] . $method_name . '</th>';
                        continue;
                    } elseif ($value['is_form']) {
                        if ($CFG->pm_editor) {
                            $method_name = Form::peLabel($value['method_id'], 'inlineForm');
                        }
                        if ($value['header_caption']) {
                            $HTML .= "<th class=\"multiple_input\">" . $value['header_caption'] . $method_name . '</th>';
                        }
                        continue;
                    }
                    if ($CFG->pm_editor) {
                        $method_name = !$value['run_in_sql'] ? Form::peLabel($value['method_id'], 'field') : Form::peLabel($value['method_id'], 'aggregate');
                    }
                    if ($value['filter']) {
                        $order_asc = $this->order_asc ? false : true;
                        if ($this->order_by == $name) {
                            $dir_img = $this->order_asc ? $CFG->up : $CFG->down;
                        } else {
                            $dir_img = false;
                        }
                        $filter_results = $_REQUEST['form_filters' . $this->i];
                        $HTML .= "<th>" . Link::url($CFG->url, $value['header_caption'] . $dir_img, false, array('filter' . $this->i => $name, 'order_by' . $this->i => $this->order_by, 'order_asc' . $this->i => $order_asc, 'is_tab' => $this->is_tab, 'inset_id' => $this->inset_id, 'inset_id_field' => $this->inset_id_field, 'inset_i' => $this->inset_i, 'form_filters' . $this->i => $filter_results, 'search_fields' . $this->i => $_REQUEST['search_fields' . $this->i]), false, false, $this->inset_i > 0 ? 'inset_area_' . $this->inset_i : 'content') . $method_name . "</th>";
                    } else {
                        $HTML .= "<th>" . $value['header_caption'] . $method_name . '</th>';
                    }
                }
            }
            $HTML .= $this->show_buttons ? "<th>&nbsp;</th>" : '';
            $HTML .= '</tr>';
            if (is_array($data)) {
                $alt = false;
                foreach ($data as $row) {
                    $alt = $alt ? false : 'alt';
                    if ($this->alert_condition1) {
                        $condition = String::doFormulaReplacements($this->alert_condition1, $row, 1);
                        $alert_class1 = eval("if ({$condition}) { return 1;} else { return 0;}") ? 'alert1' : '';
                    }
                    if ($this->alert_condition2) {
                        $condition = String::doFormulaReplacements($this->alert_condition2, $row, 1);
                        $alert_class2 = eval("if ({$condition}) { return 1;} else { return 0;}") ? 'alert2' : '';
                    }
                    $HTML .= '<tr class="' . $alt . ' ' . $alert_class1 . ' ' . $alert_class2 . '">';
                    if (!is_array($this->fields)) {
                        continue;
                    }
                    if ($CFG->backstage_mode && !$this->links_out && $this->show_buttons && $CFG->is_ctrl_panel != 'Y') {
                        $HTML .= "<td><label for=\"checkbox{$row['id']}\"/><input id=\"checkbox{$row['id']}\" type=\"checkbox\" value=\"{$row['id']}\" class=\"grid_select checkbox_input\"/></td>";
                    }
                    foreach ($this->fields as $name => $properties) {
                        $key = $name;
                        if (strstr($name, 'lll')) {
                            $name_parts = explode('lll', $name);
                            $name = $name_parts[0];
                        }
                        if ($this->inset_id > 0) {
                            if ($properties['name'] == $this->inset_id_field) {
                                continue;
                            }
                            if (strstr($this->inset_id_field, '.')) {
                                $inset_field_parts = explode('.', $this->inset_id_field);
                                if ($properties['subtable'] == $inset_field_parts[0] && (in_array($inset_field_parts[1], $properties['subtable_fields']) || $inset_field_parts[1] == 'id')) {
                                    continue;
                                }
                            }
                        }
                        $value = $row[$key];
                        $link_id = $row[$name . '_id'] ? $row[$name . '_id'] : $value;
                        $class = $properties['class'] ? "class=\"{$properties['class']}\"" : '';
                        $HTML .= "<td {$class}>";
                        if (!empty($properties['is_media'])) {
                            reset($CFG->image_sizes);
                            $m_values = explode('|||', $value);
                            $m_size = !empty($properties['media_size']) ? $properties['media_size'] : key($CFG->image_sizes);
                            $m_limit = !empty($properties['media_amount']) ? $properties['media_amount'] : 1;
                            $HTML .= Gallery::multiple($properties['subtable'], $row['id'], $properties['name'], $properties['media_size'], 0, false, $properties['media_amount'], false, false, true);
                        } elseif ($properties['is_op'] && !$properties['run_in_sql']) {
                            $value1 = number_format(self::doOperation($key, $properties, $row), 2);
                            if (is_array($page_total)) {
                                if (array_key_exists($name, $page_total)) {
                                    $page_total[$key] += $value1;
                                }
                            }
                            if (is_array($page_avg)) {
                                if (array_key_exists($name, $page_avg)) {
                                    $page_avg[$key][] = $value1;
                                }
                            }
                            $HTML .= $value1;
                        } elseif ($properties['is_form']) {
                            if (!$properties['header_caption']) {
                                continue;
                            }
                            $HTML .= '<div>';
                            if (!$ref) {
                                $ref = new ReflectionClass('Form');
                                if (is_array($properties['inputs_array'])) {
                                    foreach ($properties['inputs_array'] as $method => $args) {
                                        $method_parts = explode('|', $method);
                                        $method1 = $method_parts[0];
                                        $params = $ref->getMethod($method1)->getParameters();
                                        if (is_array($params)) {
                                            $i = 0;
                                            foreach ($params as $param) {
                                                $param_name = $param->getName();
                                                if ($param_name == 'value') {
                                                    $i_methods[$method]['value'] = $i;
                                                } elseif ($param_name == 'static') {
                                                    $i_methods[$method]['static'] = $i;
                                                } elseif ($param_name == 'j') {
                                                    $i_methods[$method]['j'] = $i;
                                                } elseif ($param_name == 'checked') {
                                                    $i_methods[$method]['checked'] = $i;
                                                } elseif ($param_name == 'grid_input') {
                                                    $i_methods[$method]['grid_input'] = $i;
                                                } elseif ($param_name == 'is_current_timestamp') {
                                                    $i_methods[$method]['is_current_timestamp'] = $i;
                                                }
                                                $i++;
                                            }
                                        }
                                    }
                                }
                            }
                            if (!empty($properties['insert_new_record_when'])) {
                                $properties['insert_new_record_when'] = String::replaceConditionals('(' . $properties['insert_new_record_when'] . ')', $row, $properties['f_id_field']);
                                $result = eval("if ({$properties['insert_new_record_when']}) { return 0;} else { return 1;}");
                            }
                            $i_table = !empty($properties['table']) ? $properties['table'] : $this->table;
                            $i_f_id = $properties['f_id'] ? $row[str_replace('[', '', str_replace(']', '', $properties['f_id']))] : $row['id'];
                            if (!$result) {
                                $i_row = DB::getRecord($i_table, 0, $row['id'], 1, $properties['f_id_field'], $properties['order_by'], $properties['order_asc']);
                            } else {
                                $i_row = false;
                            }
                            $HTML .= '
							<input type="hidden" name="iform_table' . $this->i . '[' . $row['id'] . ']" value="' . $i_table . '" />
							<input type="hidden" name="iform_id' . $this->i . '[' . $row['id'] . ']" value="' . $i_row['id'] . '" />';
                            if ($i_row) {
                                $HTML .= '<input type="hidden" name="iform_action' . $this->i . '[' . $row['id'] . ']" value="edit" />';
                            } else {
                                $HTML .= '<input type="hidden" name="iform_action' . $this->i . '[' . $row['id'] . ']" value="new" />';
                            }
                            if (is_array($properties['inputs_array'])) {
                                foreach ($properties['inputs_array'] as $method => $args) {
                                    $method_parts = explode('|', $method);
                                    $method1 = $method_parts[0];
                                    $CFG->method_id = $args['pm_method_id'];
                                    unset($args['pm_method_id']);
                                    unset($args['show_total']);
                                    $args1 = $args;
                                    $args = array_values($args);
                                    $i_value = $i_methods[$method]['value'];
                                    $i_checked = $i_methods[$method]['checked'];
                                    $i_static = $i_methods[$method]['static'];
                                    $i_j = $i_methods[$method]['j'];
                                    $i_is_current_timestamp = $i_methods[$method]['is_current_timestamp'];
                                    $input_name = $args[0];
                                    $args[$i_static] = 1;
                                    $args[$i_j] = $input_name;
                                    $args[0] = $row['id'];
                                    if ($method1 == 'textInput') {
                                        $args[13] = '';
                                        ksort($args);
                                    }
                                    if ($method1 == 'hiddenInput') {
                                        $args[8] = '';
                                        $args[$i_is_current_timestamp] = $args1['is_current_timestamp'];
                                        ksort($args);
                                    }
                                    if ($args1['show_total']) {
                                        $totals[$input_name][] = $row[$input_name];
                                    }
                                    if ($method1 == 'checkBox') {
                                        $args[$i_checked] = $i_row[$input_name];
                                    } else {
                                        $args[$i_value] = $i_row[$input_name];
                                    }
                                    if (!$class_instance) {
                                        $CFG->form_output_started = true;
                                        $class_instance = $ref->newInstanceArgs(array('grid_form_' . $this->table . $this->i));
                                    }
                                    $method_instance = $ref->getMethod($method1);
                                    $HTML .= '<div class="col" id="' . $properties['method_id'] . '">' . $method_instance->invokeArgs($class_instance, $args) . '</div>';
                                }
                            }
                            if ($class_instance) {
                                $CFG->o_method_suppress = true;
                                $method_instance = $ref->getMethod('hiddenInput');
                                $HTML .= $method_instance->invokeArgs($class_instance, array($row['id'], 0, $i_f_id, false, false, false, 1, $properties['f_id_field']));
                                $CFG->o_method_suppress = false;
                            }
                            $HTML .= '<div class="clear"></div>';
                            $HTML .= '</div>';
                        } else {
                            $value = self::detectData($key, $value, $fields, $foreign_dates);
                            if (!empty($properties['link_url'])) {
                                $action = $CFG->backstage_mode ? '&action=record' : '';
                                $value = str_replace('|||', ' ', $value);
                                if (!empty($value)) {
                                    $HTML .= Link::url($properties['link_url'], $value, "id={$link_id}&is_tab={$properties['link_is_tab']}{$action}", false, false, 'content');
                                }
                            } else {
                                $HTML .= str_ireplace('|||', ' ', $value);
                            }
                            if (is_array($page_total)) {
                                if (array_key_exists($name, $page_total)) {
                                    $page_total[$key] += $value;
                                }
                            }
                            if (is_array($page_avg)) {
                                if (array_key_exists($name, $page_avg)) {
                                    $page_avg[$key][] = $value;
                                }
                            }
                        }
                        $HTML .= "</td>";
                    }
                    if ($this->show_buttons) {
                        $HTML .= '<td><nobr>';
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 0) {
                            $HTML .= Link::url($this->link_url, false, 'id=' . $row['id'] . '&action=record&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1) {
                            $HTML .= Link::url($this->link_url, false, 'id=' . $row['id'] . '&action=form&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1 && !$this->links_out) {
                            $HTML .= '<a href="#" title="' . $CFG->delete_hover_caption . '" onclick="gridDelete(' . $row['id'] . ',\'' . $this->table . '\',this)" class="delete"></a></nobr></td>';
                        }
                    }
                    $HTML .= '</tr>';
                }
            } else {
                $HTML .= '<tr><td colspan="' . (count($this->fields) + 2) . '">' . $CFG->grid_no_results . '</td></tr>';
            }
            if ($page_total || $page_avg) {
                $HTML .= '<tr>';
                if ($this->show_buttons) {
                    $HTML .= '<td></td>';
                }
                foreach ($this->fields as $name => $properties) {
                    if ($page_total[$name]) {
                        $subtotal = $page_total[$name];
                        $subtotal = stristr($fields[$name]['Type'], 'double') ? number_format($subtotal, 2) : $subtotal;
                        $subtotals[$name] = $subtotal;
                    } else {
                        $subtotal = false;
                    }
                    if ($page_avg[$name]) {
                        $subavg = array_sum($page_avg[$name]) / count($page_avg[$name]);
                        $subavg = stristr($fields[$name]['Type'], 'double') ? number_format($subavg, 2) : $subavg;
                        $subavgs[$name] = $subavg;
                    } else {
                        $subavg = false;
                    }
                }
                $subtotals = $subtotals ? $subtotals : array();
                $subavgs = $subavgs ? $subavgs : array();
                $subs = array_merge($subtotals, $subavgs);
                foreach ($this->fields as $name => $properties) {
                    $sub = $subs[$name] ? $subs[$name] : false;
                    $HTML .= '<td class="subtotal">' . (is_numeric($sub) ? number_format($sub, 2) : $sub) . '</td>';
                }
                if ($this->show_buttons) {
                    $HTML .= '<td class="subtotal"><em>' . ($page_total ? $CFG->subtotal_label : '') . ($page_total && $page_avg ? '/' : '') . ($page_avg ? $CFG->subavg_label : '') . '</em></td>';
                }
                $HTML .= '</tr>';
            }
            if ($grand_total || $grand_avg) {
                $HTML .= '<tr>';
                if ($this->show_buttons) {
                    $HTML .= '<td class="total"></td>';
                }
                foreach ($this->fields as $name => $properties) {
                    if ($properties['is_op'] && !$properties['run_in_sql']) {
                        continue;
                    }
                    if (is_array($grand_total)) {
                        if (array_key_exists($name, $grand_total)) {
                            $total = array_key_exists($name, $grand_total) ? number_format(DB::getTotal($properties, $this->table), 2) : false;
                            $totals[$name] = $total;
                        }
                    }
                    if (is_array($grand_avg)) {
                        if (array_key_exists($name, $grand_avg)) {
                            //$avg = (array_key_exists($name,$grand_avg)) ? number_format(DB::get($this->table,array($this->table.'.'.$name),$page,$this->rows_per_page,$this->order_by,$this->order_asc,0,$this->filter_results,$this->inset_id,$this->inset_id_field,0,1),2) : false;
                            $avg = array_key_exists($name, $grand_avg) ? number_format(DB::getAverage($properties, $this->table), 2) : false;
                            $totals[$name] = $avg;
                        }
                    }
                }
                foreach ($this->fields as $name => $properties) {
                    if ($properties['is_op'] && !$properties['run_in_sql']) {
                        /*
                        $formula = $properties['formula'];
                        foreach ($totals as $o_name => $o_value) {
                        	$formula = str_replace($o_name,str_replace(',','',$o_value),$formula);
                        }
                        $total = eval("return $formula ;");
                        */
                        $total = false;
                    } else {
                        if ($totals[$name]) {
                            $total = $totals[$name];
                        } else {
                            $total = false;
                        }
                    }
                    $HTML .= '<td class="total">' . (is_numeric($total) ? number_format($total, 2) : $total) . '</td>';
                }
                if ($this->show_buttons) {
                    $HTML .= '<td class="total"><em>' . ($grand_total ? $CFG->total_label : '') . ($grand_total && $grand_avg ? '/' : '') . ($grand_avg ? $CFG->avg_label : '') . '</em></td>';
                }
                $HTML .= '</tr>';
            }
            $HTML .= '</table>';
        }
        $pagination = Grid::pagination($page, $total_rows);
        if ($this->grid_label) {
            if ($CFG->pm_editor) {
                $method_name = Form::peLabel($this->grid_label['method_id'], 'gridLabel');
            }
            $grid_label = $this->grid_label['text'] . ' ' . $method_name;
        } else {
            $grid_label = Ops::getPageTitle();
        }
        Grid::show_filters();
        Grid::show_errors();
        $amount = $total_rows > 0 ? '(' . $total_rows . ')' : false;
        if (!($this->inset_id > 0 || $CFG->is_form_inset)) {
            echo '
			<div class="area full_box" id="grid_' . $this->i . '">
				<h2>' . $grid_label . ' ' . $amount . '</h2>
				<div class="box_bar"></div>
				<div class="box_tl"></div>
				<div class="box_tr"></div>
				<div class="box_bl"></div>
				<div class="box_br"></div>
				<div class="t_shadow"></div>
				<div class="r_shadow"></div>
				<div class="b_shadow"></div>
				<div class="l_shadow"></div>
				<div class="box_b"></div>
				<div class="grid_buttons">
				' . $pagination . '';
            if (is_array($this->modes)) {
                if (count($this->modes) > 1) {
                    echo '<div class="modes">';
                    foreach ($this->modes as $mode => $enabled) {
                        $class1 = $mode == $this->mode ? 'active_view' : false;
                        if ($mode == 'table') {
                            $class = 'switch_table';
                            $caption = $CFG->switch_to_table;
                        } elseif ($mode == 'list') {
                            $class = 'switch_list';
                            $label = $CFG->switch_to_list;
                        } elseif ($mode == 'graph') {
                            $class = 'switch_graph';
                            $label = $CFG->switch_to_graph;
                        } elseif ($mode == 'graph_line') {
                            $class = 'switch_graph_line';
                            $label = $CFG->switch_to_graph_line;
                        } elseif ($mode == 'graph_pie') {
                            $class = 'switch_graph_pie';
                            $label = $CFG->switch_to_graph_pie;
                        }
                        echo Link::url($CFG->url, false, false, array('page' . $this->i => $page, 'p_bypass' . $this->i => 1, 'mode' . $this->i => $mode), true, 'content', $class . ' ' . $class1, false, false, false, false, $label) . ' ';
                    }
                    echo '</div>';
                }
            }
            if (!$this->links_out && $this->show_buttons && $CFG->is_ctrl_panel != 'Y') {
                echo '<div class="button before"></div>';
                if (is_array($this->fields)) {
                    foreach ($this->fields as $properties) {
                        if ($properties['is_form']) {
                            $i_name = !$properties['button_submit_all'] ? $properties['name'] : 'all';
                            echo '<a href="#" onclick="gridSubmitForm(\'' . $this->table . $this->i . '\')" class="button"><div class="save"></div>' . $properties['save_button_caption'] . '</a>';
                            if ($properties['button_submit_all']) {
                                break;
                            }
                        }
                    }
                }
                if (array_key_exists('is_active', $fields)) {
                    echo '<a class="button" href="#" onclick="gridSetActive(\'' . $this->table . '\',1)">' . $CFG->grid_activate_button . '</a>';
                    echo '<a class="button" href="#" onclick="gridSetActive(\'' . $this->table . '\')">' . $CFG->grid_deactivate_button . '</a>';
                }
                echo Link::url($this->link_url, '<div class="add_new"></div>' . $CFG->add_new_caption, '&action=form&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'button') . '<a class="button last" href="#" onclick="gridDeleteSelection(\'' . $this->table . '\')"><div class="delete"></div> ' . $CFG->delete_button_label . '</a>';
                echo '<div class="button after"></div>';
            }
            echo '
				</div>
				<div class="contain">';
        }
        $HTML .= '
		<script type="text/javascript">
			$(document).ready(function() {
				$("#grid_' . $this->i . '").find("th").mouseover(function() {
					gridHighlightTH(this);
				});
				$("#grid_' . $this->i . '").find("th").mouseout(function() {
					gridUnHighlightTH(this);
				});
				$("#grid_' . $this->i . '").find("td").mouseover(function() {
					gridHighlightTD(this);
				});
				$("#grid_' . $this->i . '").find("td").mouseout(function() {
					gridUnHighlightTD(this);
				});
			';
        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) < 1) {
            $HTML .= '
				$("input").attr("disabled","disabled");
				$("select").attr("disabled","disabled");
			';
        }
        $HTML .= '
			});
		</script>';
        echo $HTML;
        if ($this->rows_per_page > 30) {
            echo $pagination;
        }
        if ($CFG->backstage_mode && User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1 && $this->inset_id === false) {
            echo "</form>";
        }
        if (!($this->inset_id > 0 || $CFG->is_form_inset)) {
            echo '</div></div>';
        }
    }
Example #6
0
 /**
  * Returns the singleton instance of this class.
  */
 public static function singleton()
 {
     if (is_null(self::$_instance)) {
         $className = __CLASS__;
         self::$_instance = new $className();
         if (isset($_SESSION[Config::get('user.session_key')])) {
             $user = User::user()->where('id', '=', $_SESSION[Config::get('user.session_key')])->first();
             if ($user) {
                 self::$_user['id'] = $user->id;
                 self::$_user['email'] = $user->email;
                 self::$_user['is_admin'] = $user->is_admin;
                 $permissions = User::permission()->select('user_permissions.permission')->distinct()->leftJoin('habtm_userroles_userusers t', 't.role_id', '=', 'user_permissions.role_id')->where('t.user_id', '=', $user->id)->get();
                 if ($permissions) {
                     foreach ($permissions as $row) {
                         self::$_user['permissions'][] = $row->permission;
                     }
                 }
             }
         }
         Log::debug('user', 'Current user ID: ' . self::$_user['id']);
     }
     return self::$_instance;
 }
Example #7
0
if(Session::exists("home")){
    echo "session exists";
    echo Session::get("home");
}
*/
//-------------------------------------------------------------------------------------------------------------------
if (!Session::exists(Config::get("session/session_name"))) {
    echo "<h4> Hello </h4>";
}
$user = new User();
if (Session::exists("home")) {
    echo Session::flash("home");
}
if ($user->isLoggedIn()) {
    echo "Current user: "******"<br>";
    if ($user->permission("admin")) {
        echo "You are administrator <br> <br>";
    }
    echo "<a href='update.php'> Update informations </a> <br>";
    echo "<a href='changepassword.php'> Change password </a> <br>";
    echo "<a href='logout.php'> Logout </a> <br>";
} else {
    echo "You need to <a href='login.php'> log in </a> or <a href='register.php'> register </a>";
}
echo "<br><br> Default user and pass: username password. <br> <br>";
?>




Example #8
0
    function display()
    {
        global $CFG;
        if (!is_array($this->tables)) {
            return false;
        }
        self::getData();
        self::getFolders();
        if ($this->mode == 'icons') {
            if (is_array($this->folders['path'])) {
                $this->folders['path'] = array_reverse($this->folders['path']);
            }
            $this->folders['path'][] = $this->folders['this'];
            foreach ($this->folders['path'] as $folder) {
                $path .= '/' . $folder['folder_name'];
            }
        } else {
            $path = '/' . $CFG->filter_submit_text;
        }
        if (!$this->bypass) {
            self::show_filters();
            $HTML .= '
			<div class="' . $this->class . '">
				<table>
					<tr>
						<td class="bar" colspan="2">
							<a class="m_back" title="' . $CFG->back . '" onclick="file_manager.last()"></a>
							<a class="m_forward" title="' . $CFG->forward . '" onclick="file_manager.next()"></a>
							<a class="m_up" title="' . $CFG->up_directory . '" onclick="file_manager.openFolder(' . $this->folders['up']['id'] . ')"></a>
							<a class="m_add_folder" title="' . $CFG->add_directory . '" onclick="file_manager.addFolder()"></a>';
            if ($this->tables) {
                foreach ($this->tables as $table => $properties) {
                    $table1 = substr($table, -1) == 's' ? ucfirst(substr($table, 0, -1)) : ucfirst($table);
                    $HTML .= '<a class="m_add_file" title="' . $CFG->add_new_caption . ' ' . $table1 . '" onclick="file_manager.addFile(\'' . $table . '\')"></a>';
                }
            }
            $HTML .= '		
							<div id="fm_path" class="fm_path">' . $path . '</div>';
            if (User::$info['is_admin'] == 'Y' || !$this->only_admin && key($this->download_group) == User::$info['f_id']) {
                $HTML .= '
							<div class="fm_download"><a href="#" onclick="file_manager.downloadResults();return false;">' . ($this->mode == 'icons' ? $CFG->download_all : $CFG->download_results) . '</a><iframe class="fm_download_iframe" src="" name="download"></iframe></div>';
            }
            $HTML .= '
							<div class="clear"></div>
						</td>
					</tr>
					<tr>
						<td class="tree">';
            if (is_array($this->folders['path'])) {
                $last_p_id = $this->folders['path'][0]['id'];
            }
            $has_sub = self::hasSubfolders($id) ? 'this' : 'false';
            $no_triangle = $has_sub == 'false' ? 'not' : '';
            $down = $last_p_id > 0 && $id == $last_p_id ? 1 : false;
            $HTML .= '
			<div class="folder_container">
				<input type="hidden" id="id" value="0" />
				<div id="triangle" class="triangle' . $down . ' ' . $no_triangle . '" onclick="file_manager.showSubfolders(0,' . $has_sub . ')"></div>
				<div class="folder home" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(0,' . $has_sub . ')"></div>
				<div class="desc" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(0,' . $has_sub . ')">/</div>
				<div class="clear"></div>
			</div>';
            if (is_array($this->folders['top_level'])) {
                foreach ($this->folders['top_level'] as $id => $row) {
                    $has_sub = self::hasSubfolders($id) ? 'this' : 'false';
                    $no_triangle = $has_sub == 'false' ? 'not' : '';
                    $down = $last_p_id > 0 && $id == $last_p_id ? 1 : false;
                    $HTML .= '
					<div class="folder_container">
						<input type="hidden" id="id" value="' . $row['id'] . '" />
						<div id="triangle" class="triangle' . $down . ' ' . $no_triangle . '" onclick="file_manager.showSubfolders(' . $row['id'] . ',' . $has_sub . ')"></div>
						<div class="folder" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $row['id'] . ',' . $has_sub . ')"></div>
						<div class="desc" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $row['id'] . ',' . $has_sub . ')">' . $row['folder_name'] . '</div>
						<div class="clear"></div>';
                    if ($last_p_id > 0 && $id == $last_p_id) {
                        $i = 0;
                        foreach ($this->folders['path'] as $key => $sub) {
                            if (!($key > 0)) {
                                continue;
                            }
                            $has_sub = self::hasSubfolders($id) ? 'this' : 'false';
                            $no_triangle = $has_sub == 'false' ? 'not' : '';
                            $down = $sub['id'] == $this->folders['this']['id'] ? false : 1;
                            $HTML .= '
							<div class="folder_container indent">
								<input type="hidden" id="id" value="' . $sub['id'] . '" />
								<div id="triangle" class="triangle' . $down . ' ' . $no_triangle . '" onclick="file_manager.showSubfolders(' . $sub['id'] . ',' . $has_sub . ')"></div>
								<div class="folder" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $sub['id'] . ',' . $has_sub . ')"></div>
								<div class="desc" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $sub['id'] . ',' . $has_sub . ')">' . $sub['folder_name'] . '</div>
								<div class="clear"></div>';
                            $i++;
                        }
                        for ($j = 0; $j < $i; $j++) {
                            $HTML .= '</div>';
                        }
                    }
                    $HTML .= '</div>';
                }
            }
            $HTML .= '
						</td>
						<td class="navigator" id="navigator">';
        }
        if ($this->data_download) {
            foreach ($this->data_download as $d_table => $d_ids) {
                $HTML .= '<input type="hidden" class="download_ids" id="download_' . $d_table . '" value="' . @implode('|', $d_ids) . '" />';
            }
        }
        $HTML .= '
		<input type="hidden" id="folder_table" value="' . $this->folder_table . '" />
		<input type="hidden" id="current_id" value="' . $this->current_folder_id . '" />
		<input type="hidden" id="current_url" value="' . $CFG->url . '" />
		<input type="hidden" id="is_tab" value="' . $CFG->is_tab . '" />';
        if ($this->mode == 'icons') {
            if ($this->tables) {
                foreach ($this->tables as $table => $properties) {
                    $HTML .= '<input type="hidden" id="folder_link" value="&action=form&p_id=' . $this->current_folder_id . '" />';
                    $HTML .= '<input type="hidden" id="' . $table . '_link" value="current_url=' . $properties['url'] . '&action=form&is_tab=' . $properties['link_is_tab'] . '&' . $properties['url'] . '[' . $properties['folder_field'] . ']=' . $this->current_folder_id . '" />';
                    $HTML .= '<input type="hidden" id="' . $table . '_target" value="' . $properties['target_elem_id'] . '" />';
                }
            }
            if (!($this->current_folder_id > 0) && $this->folders['top_level']) {
                foreach ($this->folders['top_level'] as $folder) {
                    $HTML .= '
					<div class="folder_container">
						<div class="ops">';
                    if (User::permission(0, 0, $this->folder_table) > 0) {
                        $HTML .= Link::url($this->folder_table, false, 'id=' . $folder['id'] . '&action=record&is_tab=' . $folder['link_is_tab'], false, false, 'edit_box', 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                    }
                    if (User::permission(0, 0, $this->folder_table) > 1) {
                        $HTML .= Link::url($this->folder_table, false, 'id=' . $folder['id'] . '&action=form&is_tab=' . $folder['link_is_tab'], false, false, 'edit_box', 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                    }
                    if (User::permission(0, 0, $this->folder_table) > 1) {
                        $HTML .= '<a href="#" title="' . $CFG->delete_hover_caption . '" onclick="file_manager.deleteThis(' . $folder['id'] . ',\'' . $this->folder_table . '\',this)" class="delete"></a>';
                    }
                    $HTML .= '
						</div>
						<div class="folder" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $folder['id'] . ')"></div>
						<div class="desc" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $folder['id'] . ')">' . $folder['folder_name'] . '</div>
						<input type="hidden" id="id" value="' . $folder['id'] . '" />
					</div>';
                }
            } elseif ($this->folders['children']) {
                foreach ($this->folders['children'] as $folder) {
                    $HTML .= '
					<div class="folder_container">
						<div class="ops">';
                    if (User::permission(0, 0, $this->folder_table) > 0) {
                        $HTML .= Link::url($this->folder_table, false, 'id=' . $folder['id'] . '&action=record', false, false, 'edit_box', 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                    }
                    if (User::permission(0, 0, $this->folder_table) > 1) {
                        $HTML .= Link::url($this->folder_table, false, 'id=' . $folder['id'] . '&action=form', false, false, 'edit_box', 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                    }
                    if (User::permission(0, 0, $this->folder_table) > 1) {
                        $HTML .= '<a href="#" title="' . $CFG->delete_hover_caption . '" onclick="file_manager.deleteThis(' . $folder['id'] . ',\'' . $this->folder_table . '\',this)" class="delete"></a>';
                    }
                    $HTML .= '
						</div>
						<div class="folder" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $folder['id'] . ')"></div>
						<div class="desc" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $folder['id'] . ')">' . $folder['folder_name'] . '</div>
						<input type="hidden" id="id" value="' . $folder['id'] . '" />
					</div>';
                }
            }
            if ($this->data) {
                foreach ($this->data as $file) {
                    if ($file['alert_condition1']) {
                        $file_row = DB::getRecord($file['table'], $file['id']);
                        $condition = String::doFormulaReplacements($file['alert_condition1'], $file_row, 1);
                        $alert_class1 = eval("if ({$condition}) { return 1;} else { return 0;}") ? 'alert1' : '';
                    }
                    if ($file['alert_condition2']) {
                        $file_row = is_array($file_row) ? $file_row : DB::getRecord($file['table'], $file['id']);
                        $condition = String::doFormulaReplacements($file['alert_condition2'], $file_row, 1);
                        $alert_class2 = eval("if ({$condition}) { return 1;} else { return 0;}") ? 'alert2' : '';
                    }
                    $HTML .= '
					<div class="file_container ' . $alert_class1 . ' ' . $alert_class2 . '">
						<div class="ops">';
                    if (User::permission(0, 0, $file['url']) > 0) {
                        $HTML .= Link::url($file['url'], false, 'id=' . $file['id'] . '&action=record&is_tab=' . $file['link_is_tab'], false, false, $file['target_elem_id'], 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                    }
                    if (User::permission(0, 0, $file['url']) > 1) {
                        $HTML .= Link::url($file['url'], false, 'id=' . $file['id'] . '&action=form&is_tab=' . $file['link_is_tab'], false, false, $file['target_elem_id'], 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                    }
                    if (User::permission(0, 0, $file['url']) > 1) {
                        $HTML .= '<a href="#" title="' . $CFG->delete_hover_caption . '" onclick="file_manager.deleteThis(' . $file['id'] . ',\'' . $file['table'] . '\',this)" class="delete"></a>';
                    }
                    $is_tab = $file['link_is_tab'] ? $file['link_is_tab'] : 'false';
                    $HTML .= '
						</div>
						<div class="file" onclick="file_manager.select(this,event);" ondblclick="file_manager.showFile(\'' . $file['url'] . '\',' . $file['id'] . ',' . $is_tab . ',\'' . $file['target_elem_id'] . '\');"></div>
						<div class="desc" onclick="file_manager.select(this,event);" ondblclick="file_manager.showFile(\'' . $file['url'] . '\',' . $file['id'] . ',' . $is_tab . ',\'' . $file['target_elem_id'] . '\');">' . $file['file_name'] . '</div>
						<input type="hidden" id="id" value="' . $file['id'] . '" />
						<input type="hidden" id="table" value="' . $file['table'] . '" />
						<input type="hidden" id="folder_field" value="' . $file['folder_field'] . '" />
					</div>';
                }
            }
        } elseif ($this->mode == 'search') {
            if ($this->data) {
                foreach ($this->data as $row) {
                    $k = $row['file_name'];
                    $all_data[$k . '_fi'] = $row;
                }
            }
            if ($this->folders1) {
                foreach ($this->folders1 as $row) {
                    $k = $row['folder_name'];
                    $all_data[$k . '_fo'] = $row;
                }
            }
            if ($all_data) {
                ksort($all_data);
                $HTML .= '<div class="search">';
                foreach ($all_data as $row) {
                    if (array_key_exists('file_name', $row)) {
                        if ($row['alert_condition1']) {
                            $file_row = DB::getRecord($row['table'], $row['id']);
                            $condition = String::doFormulaReplacements($row['alert_condition1'], $file_row, 1);
                            $alert_class1 = eval("if ({$condition}) { return 1;} else { return 0;}") ? 'alert1' : '';
                        }
                        if ($row['alert_condition2']) {
                            $file_row = is_array($file_row) ? $file_row : DB::getRecord($row['table'], $row['id']);
                            $condition = String::doFormulaReplacements($row['alert_condition2'], $file_row, 1);
                            $alert_class2 = eval("if ({$condition}) { return 1;} else { return 0;}") ? 'alert2' : '';
                        }
                        $is_tab = $row['link_is_tab'] ? $row['link_is_tab'] : 'false';
                        $HTML .= '<div class="search_container ' . $alert_class1 . ' ' . $alert_class2 . '" onclick="file_manager.select(this,event);" ondblclick="file_manager.showFile(\'' . $row['url'] . '\',' . $row['id'] . ',' . $is_tab . ',\'' . $row['target_elem_id'] . '\');">';
                        $HTML .= '
							<div class="file"></div>
							<div class="desc">' . $row['file_name'] . '</div>
							<input type="hidden" id="id" value="' . $row['id'] . '" />
							<input type="hidden" id="table" value="' . $row['table'] . '" />
							<input type="hidden" id="folder_field" value="' . $row['folder_field'] . '" />
							<div class="ops1">';
                        if (User::permission(0, 0, $row['url']) > 0) {
                            $HTML .= Link::url($row['url'], false, 'id=' . $row['id'] . '&action=record&is_tab=' . $row['link_is_tab'], false, false, $row['target_elem_id'], 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $row['url']) > 1) {
                            $HTML .= Link::url($row['url'], false, 'id=' . $row['id'] . '&action=form&is_tab=' . $row['link_is_tab'], false, false, $row['target_elem_id'], 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $row['url']) > 1) {
                            $HTML .= '<a href="#" title="' . $CFG->delete_hover_caption . '" onclick="file_manager.deleteThis(' . $row['id'] . ',\'' . $row['table'] . '\',this)" class="delete"></a>';
                        }
                        $HTML .= "</div></div>";
                    } else {
                        $HTML .= '<div class="search_container" onclick="file_manager.select(this,event);" ondblclick="file_manager.openFolder(' . $row['id'] . ')">';
                        $HTML .= '
						<div class="folder"></div>
						<div class="desc">' . $row['folder_name'] . '</div>
						<input type="hidden" id="id" value="' . $row['id'] . '" />
						<div class="ops1">';
                        if (User::permission(0, 0, $this->folder_table) > 0) {
                            $HTML .= Link::url($this->folder_table, false, 'id=' . $row['id'] . '&action=record', false, false, 'edit_box', 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->folder_table) > 1) {
                            $HTML .= Link::url($this->folder_table, false, 'id=' . $row['id'] . '&action=form', false, false, 'edit_box', 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->folder_table) > 1) {
                            $HTML .= '<a href="#" title="' . $CFG->delete_hover_caption . '" onclick="file_manager.deleteThis(' . $row['id'] . ',\'' . $this->folder_table . '\',this)" class="button"></a>';
                        }
                        $HTML .= '
						</div>';
                        $HTML .= '</div>';
                    }
                }
                $HTML .= '</div>';
            }
        }
        if (!$CFG->pm_editor) {
            $HTML .= '
			<script language="text/javascript">
				' . (!$this->n_or_b ? 'file_manager.addHistory(' . $this->current_folder_id . ');' : '') . '
				file_manager.setPath("' . $path . '");
				$("#navigator").click(function() {
					file_manager.unselect();
				});
				$(".tree").click(function() {
					file_manager.unselect();
				});
				file_manager.startSelectable();
			</script>
			';
        }
        if (!$this->bypass) {
            $HTML .= '		<div class="clear"></div>
						</td>
					</tr>
				</table>
			</div>';
        }
        echo $HTML;
    }
Example #9
0
    function display()
    {
        global $CFG;
        self::getSteps();
        $HTML = '
		<div class="flow_chart">
			<table>
				<tr>
					<td class="bar">
						<a class="add_step" title="' . $CFG->add_step . '" onclick="flow_chart.addStep()"></a>
						<a class="save_order" title="' . $CFG->save_order . '" onclick="flow_chart.saveOrder()"></a>
					</td>
				</tr>
				<tr>
					<td class="navigator" id="navigator">
						<input type="hidden" id="table" value="' . $this->table . '" />
						<input type="hidden" id="current_url" value="' . $CFG->url . '" />
						<input type="hidden" id="is_tab" value="' . $CFG->is_tab . '" />';
        if ($this->steps) {
            foreach ($this->steps as $i => $step) {
                $HTML .= '
				<div class="step_container">
					<div class="ops">';
                if (User::permission(0, 0, $this->table, false, $this->url_is_tab) > 0) {
                    $HTML .= Link::url($this->table, false, 'id=' . $step['id'] . '&action=record&is_tab=' . $this->url_is_tab, false, false, 'edit_box', 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                }
                if (User::permission(0, 0, $this->table, false, $this->url_is_tab) > 1) {
                    $HTML .= Link::url($this->table, false, 'id=' . $step['id'] . '&action=form&is_tab=' . $this->url_is_tab, false, false, 'edit_box', 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                }
                if (User::permission(0, 0, $this->table, false, $this->url_is_tab) > 1) {
                    $HTML .= '<a href="#" title="' . $CFG->delete_hover_caption . '" onclick="flow_chart.deleteThis(' . $step['id'] . ',\'' . $this->table . '\',this)" class="delete"></a>';
                }
                $HTML .= '
					</div>
					<div class="step" onclick="flow_chart.select(this,event);" ondblclick="flow_chart.open(' . $step['id'] . ')"></div>
					<div class="desc" onclick="flow_chart.select(this,event);" ondblclick="flow_chart.open(' . $step['id'] . ')">' . $step['name'] . '</div>
					<input type="hidden" id="id" value="' . $step['id'] . '" />
				</div>';
                if ($this->steps[$i + 1]) {
                    $HTML .= '<div class="step_link"></div>';
                }
            }
        }
        if (!$CFG->pm_editor) {
            $HTML .= '
			<script language="text/javascript">
				$("#navigator").click(function() {
					flow_chart.unselect();
				});
				flow_chart.startSortable();
			</script>
			';
        }
        $HTML .= '
						<div class="clear"></div>
					</td>
				</tr>
			</table>
		</div>
		';
        echo $HTML;
    }
Example #10
0
    function __construct($url, $action, $is_tab = false, $editor_mode = false)
    {
        global $CFG;
        if ($url && !User::permission(false, false, $url)) {
            return false;
        }
        date_default_timezone_set($CFG->default_timezone);
        String::magicQuotesOff();
        $page_id = is_numeric($url) ? $url : Control::getPageId($url, $is_tab);
        if (!($page_id > 0)) {
            return false;
        }
        $page_info = $is_tab ? DB::getRecord('admin_tabs', $page_id, 0, 1) : DB::getRecord('admin_pages', $page_id, 0, 1);
        if ($page_info['one_record'] == 'Y' && !$editor_mode) {
            $action = 'form';
            $_REQUEST['id'] = 1;
            $CFG->control_one_record = 1;
        }
        $controls = Control::getControls($page_id, $action, $is_tab);
        $CFG->editor_page_id = $page_id;
        $CFG->editor_is_tab = $is_tab;
        $CFG->is_ctrl_panel = $page_info['is_ctrl_panel'];
        if ($controls) {
            foreach ($controls as $c_id => $control) {
                $params = $control['params'];
                $is_static = $params['is_static'] == 'Y';
                $class = $params['class'];
                $CFG->control_pass_id = $params['id'];
                if ($_REQUEST['cal_bypass'] && $class != 'Calendar') {
                    continue;
                }
                if ($editor_mode) {
                    $pm_methods = array();
                    echo '<div class="pm_class_container" id="control_' . $params['id'] . '">
							<div class="control_label">' . $params['class'] . ' ' . $params['id'] . '
								<a href="#" title="' . $CFG->move_hover_caption . '" class="move_handle dont_disable"></a>
								<a class="edit dont_disable" title="' . $CFG->edit_hover_caption . '" onclick="pmControlEdit(\'control_' . $params['id'] . '\');"></a>
								<a class="delete dont_disable" title="' . $CFG->delete_hover_caption . '" onclick="pmControlDelete(\'control_' . $params['id'] . '\');"></a>
							</div>
							<input type="hidden" class="this_class" id="control_' . $params['id'] . '_class" value="' . $params['class'] . '"/>
							<input type="hidden" class="this_page_id" id="control_' . $params['id'] . '_page_id" value="' . $params['page_id'] . '"/>
							<input type="hidden" class="this_action" id="control_' . $params['id'] . '_action" value="' . $params['action'] . '"/>
							<input type="hidden" class="this_id" id="control_' . $params['id'] . '_id" value="' . $params['id'] . '"/>';
                }
                if (!$is_static) {
                    $ref = new ReflectionClass($class);
                    $args = Control::parseArguments($params['arguments'], $class, '__construct');
                    $this->class = $ref->newInstanceArgs($args);
                    if ($class == 'Form') {
                        if (!$CFG->in_include) {
                            $this->class->verify();
                            $this->class->save();
                            $this->class->show_errors();
                            $this->class->show_messages();
                            $this->class->get($page_info['url'] == 'my-account' || $url == 'my-account' ? User::$info['id'] : $_REQUEST['id']);
                        } else {
                            $this->class->get($CFG->include_id);
                        }
                        $this->class->info['p_id'] = $_REQUEST['p_id'];
                        $this->class->info['f_id'] = $_REQUEST['f_id'];
                        if ($page_info['url'] == 'my-account' || $url == 'my-account') {
                            $CFG->o_method_suppress = true;
                            $this->class->passiveField('id', 'ID');
                            $CFG->o_method_suppress = true;
                            $this->class->textInput('user', $CFG->user_username, true, false, false, false, false, false, false, false, 1, $CFG->user_unique_error);
                            $CFG->o_method_suppress = true;
                            $this->class->passwordInput('pass', $CFG->user_password, true);
                            $CFG->o_method_suppress = true;
                            $this->class->passwordInput('pass1', $CFG->user_password, true, false, false, false, false, false, 'pass');
                            $CFG->o_method_suppress = true;
                            $this->class->textInput('first_name', $CFG->user_first_name, true);
                            $CFG->o_method_suppress = true;
                            $this->class->textInput('last_name', $CFG->user_last_name, true);
                            $CFG->o_method_suppress = true;
                            $this->class->textInput('phone', $CFG->user_phone);
                            $CFG->o_method_suppress = true;
                            $this->class->textInput('email', $CFG->user_email);
                            if (User::$info['is_admin'] == 'Y') {
                                $CFG->o_method_suppress = true;
                                $this->class->selectInput('f_id', $CFG->user_group, false, $_REQUEST['f_id'], false, 'admin_groups', array('name'));
                                $CFG->o_method_suppress = true;
                                $this->class->checkBox('is_admin', $CFG->user_is_admin);
                            }
                        }
                    }
                    echo '<input type="hidden" id="control_' . $params['id'] . '_table" value="' . $args['table'] . '"/>';
                }
                if (is_array($control['methods'])) {
                    foreach ($control['methods'] as $method) {
                        if ($method['p_id'] > 0) {
                            continue;
                        }
                        //$method['method'] = ($method['method'] == 'selectInput') ? 'fauxSelect' : $method['method'];
                        $CFG->method_id = $method['id'];
                        $args = Control::parseArguments($method['arguments'], $class, $method['method']);
                        $inputs_array = self::getSubMethods($method['id'], $class);
                        if (is_array($inputs_array)) {
                            $args['inputs_array'] = $inputs_array;
                        }
                        if ($is_static) {
                            call_user_func_array("{$class}::{$method['method']}", $args);
                        } else {
                            $method_instance = $ref->getMethod($method['method']);
                            $method_instance->invokeArgs($this->class, $args);
                        }
                    }
                }
                $CFG->method_id = false;
                if ($class == 'Form' && !$CFG->pm_decouple_cancel) {
                    $this->class->cancelButton($CFG->cancel_button);
                }
                if ($class == 'Record' && !$CFG->pm_decouple_cancel) {
                    $d = new Form('dummy');
                    $d->cancelButton($CFG->ok_button);
                    $d->display();
                }
                if (!$is_static) {
                    if ($class == 'Grid') {
                        $this->class->display($_REQUEST['page' . $this->class->i]);
                    } else {
                        $this->class->display();
                    }
                }
                if ($editor_mode) {
                    echo '
					<div class="clear">&nbsp;</div></div>';
                }
                $this->class = false;
            }
        }
        if ($editor_mode) {
            echo '
			<script type="text/javascript">
				$(document).ready(function(){
					startEditor();
				});
			</script>';
        }
    }
Example #11
0
    function display()
    {
        global $CFG;
        if (!is_array($this->tables) || !is_array($this->fields)) {
            return false;
        }
        if ($CFG->pm_editor) {
            echo '</ul>';
        }
        $mode = $this->mode;
        $date = $this->date;
        $y = $this->y;
        $m = $this->m;
        $d = $this->d;
        $this->days_in_month = cal_days_in_month(0, $m, $y);
        if (!$mode || $mode == 'month') {
            $first_day = mktime(0, 0, 0, $m, 1, $y);
            $title = date('F', $first_day) . ' ' . $y;
            $day_of_week = date('w', $first_day);
            $days_array = range(1, $this->days_in_month);
            $start = $first_day;
            $end = mktime(23, 59, 59, $m, $this->days_in_month, $y);
            $next = strtotime('+1 month', $first_day);
            $next_5 = strtotime('+5 month', $first_day);
            $prev = strtotime('-1 month', $first_day);
            $prev_5 = strtotime('-5 month', $first_day);
        } elseif ($mode == 'week') {
            $day_of_week = date('w', $date);
            $first_day = date('j', strtotime('-' . $day_of_week . ' day', $date));
            $start = strtotime('-' . $day_of_week, $date);
            $end = strtotime('+' . (6 - $day_of_week), $date);
            $title = $CFG->cal_week_from . ' ' . date($CFG->default_date_format, strtotime('-' . $day_of_week . ' day', $date)) . ' ' . $CFG->cal_week_until . ' ' . date($CFG->default_date_format, strtotime('+' . (6 - $day_of_week) . ' day', $date));
            $next = strtotime('+1 week', $first_day);
            $next_5 = strtotime('+5 week', $first_day);
            $prev = strtotime('-1 week', $first_day);
            $prev_5 = strtotime('-5 week', $first_day);
            for ($i = 0; $i <= 6; $i++) {
                $days_array[] = date('j', strtotime("+{$i} day", $start));
            }
        } elseif ($mode == 'day') {
            $refer_mode = $_REQUEST['cal_' . $this->i . '_refer_mode'];
            $s_hour = $this->start_time ? $this->start_time : 0;
            $e_hour = $this->end_time ? $this->end_time : 23;
            $start = mktime(0, 0, 0, $m, $d, $y);
            $end = mktime(23, 59, 59, $m, $d, $y);
            $title = date('D F j, Y', $start);
            $next = strtotime('+1 day', $start);
            $next_5 = strtotime('+5 day', $start);
            $prev = strtotime('-1 day', $start);
            $prev_5 = strtotime('-5 day', $start);
            $days_array[] = $this->date;
        }
        $this->data = self::get($start, $end);
        if (!$this->print) {
            $day_class = $mode == 'day' ? 'calendar_day' : '';
            $HTML = "\n\t\t\t<div class=\"area full_box calendar {$class} {$day_class}\" id=\"cal_{$this->i}\">\n\t\t\t\t<h2>{$title}</h2>\n\t\t\t\t<div class=\"box_bar\"></div>\n\t\t\t\t<div class=\"box_tl\"></div>\n\t\t\t\t<div class=\"box_tr\"></div>\n\t\t\t\t<div class=\"box_bl\"></div>\n\t\t\t\t<div class=\"box_br\"></div>\n\t\t\t\t<div class=\"t_shadow\"></div>\n\t\t\t\t<div class=\"r_shadow\"></div>\n\t\t\t\t<div class=\"b_shadow\"></div>\n\t\t\t\t<div class=\"l_shadow\"></div>\n\t\t\t\t<div class=\"box_b\"></div>\n\t\t\t\t<div class=\"grid_buttons\"><div class=\"button before\"></div>";
            if (is_array($this->add_buttons)) {
                foreach ($this->add_buttons as $button) {
                    $string = $button['table'];
                    if (substr($string, -1) == 's') {
                        $string = substr($string, 0, -1);
                    }
                    $HTML .= Link::url($button['table'], '<div class="add_new"></div>' . $CFG->add_new_caption . ' ' . ucfirst($string), '&action=form&is_tab=' . $button['is_tab'], false, false, $button['target_elem_id'], 'button');
                }
            }
            $HTML .= (User::permission(0, 0, $CFG->url) > 1 ? "<a href=\"#\" onclick=\"saveCalOrder()\" class=\"button\"><div class=\"save\"></div> {$CFG->save_caption}</a>" : '') . '<a href="#" onclick="printCal(' . $this->i . ')" class="button"><div class="print"></div>' . $CFG->print_caption . '</a>';
            if ($this->mode_switching && ($mode == 'day' || $mode == 'week')) {
                $HTML .= Link::url($CFG->url, '<div class="cal_icon"></div>' . $CFG->cal_view_month, false, array('cal_' . $this->i . '_y' => date('Y', $start), 'cal_' . $this->i . '_m' => date('n', $start), 'cal_bypass' => 1, 'bypass' => 1, 'cal_' . $this->i . '_mode' => 'month'), true, 'cal_' . $this->i, 'button');
            }
            $HTML .= '
				<div class="button after"></div></div><div class="contain">' . Link::url($CFG->url, 'hidden', false, array('cal_' . $this->i . '_y' => $this->y, 'cal_' . $this->i . '_m' => $this->m, 'cal_' . $this->i . '_d' => $this->d, 'cal_bypass' => 1, 'bypass' => 1, 'mode' => $mode, 'print' => 1), true, false, 'cal_print_link', false, '_blank') . "\n\t\t\t\t<table cellspacing=\"0\">\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan=\"" . (!$mode || $mode == 'month' ? 7 : ($mode == 'week' ? 8 : 2)) . "\">\n\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t<div onclick=\"synchCalDates(" . date('Y', $prev_5) . "," . date('n', $prev_5) . "," . date('j', $prev_5) . ")\" class=\"n1 n\">" . Link::url($CFG->url, '<<', false, array('cal_' . $this->i . '_y' => date('Y', $prev_5), 'cal_' . $this->i . '_m' => date('n', $prev_5), 'cal_' . $this->i . '_d' => date('j', $prev_5), 'cal_bypass' => 1, 'bypass' => 1, 'mode' => $mode), true, 'cal_' . $this->i) . "</div>\n\t\t\t\t\t\t\t<div onclick=\"synchCalDates(" . date('Y', $prev) . "," . date('n', $prev) . "," . date('j', $prev) . ")\" class=\"n2 n\">" . Link::url($CFG->url, '<', false, array('cal_' . $this->i . '_y' => date('Y', $prev), 'cal_' . $this->i . '_m' => date('n', $prev), 'cal_' . $this->i . '_d' => date('j', $prev), 'cal_bypass' => 1, 'bypass' => 1, 'mode' => $mode), true, 'cal_' . $this->i) . "</div>\n\t\t\t\t\t\t\t<div onclick=\"synchCalDates(" . date('Y', time()) . "," . date('n', time()) . "," . date('j', time()) . ")\" class=\"n_today n\">" . Link::url($CFG->url, $CFG->cal_today, false, array('cal_' . $this->i . '_y' => date('Y', time()), 'cal_' . $this->i . '_m' => date('n', time()), 'cal_' . $this->i . '_d' => date('j', time()), 'cal_bypass' => 1, 'bypass' => 1, 'mode' => $mode), true, 'cal_' . $this->i) . "</div>\n\t\t\t\t\t\t\t<div onclick=\"synchCalDates(" . date('Y', $next) . "," . date('n', $next) . "," . date('j', $next) . ")\" class=\"n3 n\">" . Link::url($CFG->url, '>', false, array('cal_' . $this->i . '_y' => date('Y', $next), 'cal_' . $this->i . '_m' => date('n', $next), 'cal_' . $this->i . '_d' => date('j', $next), 'cal_bypass' => 1, 'bypass' => 1, 'mode' => $mode), true, 'cal_' . $this->i) . "</div>\n\t\t\t\t\t\t\t<div onclick=\"synchCalDates(" . date('Y', $next_5) . "," . date('n', $next_5) . "," . date('j', $next_5) . ")\" class=\"n4 n\">" . Link::url($CFG->url, '>>', false, array('cal_' . $this->i . '_y' => date('Y', $next_5), 'cal_' . $this->i . '_m' => date('n', $next_5), 'cal_' . $this->i . '_d' => date('j', $next_5), 'cal_bypass' => 1, 'bypass' => 1, 'mode' => $mode), true, 'cal_' . $this->i) . "</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</th>\n\t\t\t\t</tr>\n\t\t\t";
            if ($this->tokenizers && $this->mode == 'day') {
                foreach ($this->tokenizers as $t_name => $t_values) {
                    if (is_array($t_values)) {
                        $HTML .= '<tr><td class="datasets" colspan="' . (!$mode || $mode == 'month' ? 7 : ($mode == 'week' ? 8 : 2)) . '">';
                        foreach ($t_values as $t_value) {
                            $HTML .= '<div>' . $t_value . '</div>';
                        }
                        $HTML .= "</td></tr>";
                    }
                }
            }
            if (!$mode || $mode == 'month') {
                $alt = $alt ? '' : 'class="alt"';
                $HTML .= "\n\t\t\t\t\t<tr {$alt}>\n\t\t\t\t\t\t<td class=\"c_day\">{$CFG->cal_sun}</td>\n\t\t\t\t\t\t<td class=\"c_day\">{$CFG->cal_mon}</td>\n\t\t\t\t\t\t<td class=\"c_day\">{$CFG->cal_tue}</td>\n\t\t\t\t\t\t<td class=\"c_day\">{$CFG->cal_wed}</td>\n\t\t\t\t\t\t<td class=\"c_day\">{$CFG->cal_thur}</td>\n\t\t\t\t\t\t<td class=\"c_day\">{$CFG->cal_fri}</td>\n\t\t\t\t\t\t<td class=\"c_day\">{$CFG->cal_sat}</td>\n\t\t\t\t\t</tr>";
                $day_count = 1;
                $HTML .= "<tr>";
                $i = $day_of_week;
                while ($i > 0) {
                    $HTML .= '<td class="inactive"></td>';
                    $i--;
                    $day_count++;
                }
                foreach ($days_array as $day_num) {
                    $events = self::getEvents(false, false, $day_num);
                    $current = $day_num == date('j') && $m == date('n') && $y == date('Y') ? 'current' : '';
                    $HTML .= "\n\t\t\t\t\t<td class=\"{$current}\" onmouseover=\"calCellHover(this)\" onmouseout=\"calCellOut(this)\" onclick=\"calZoomDay({$this->i},'{$CFG->url}',{$CFG->is_tab},{$y},{$m},{$day_num})\">\n\t\t\t\t\t\t<div class=\"wrap\">\n\t\t\t\t\t\t\t<div class=\"day_num\">{$day_num}</div>";
                    if (is_array($events)) {
                        foreach ($events as $k => $dataset) {
                            @reset($this->tokenizers);
                            $tk = @key($this->tokenizers);
                            if (count($this->tokenizers[$tk]) > 1) {
                                $HTML .= '<div class="token_label">' . $this->tokenizers[$tk][$k] . '</div>';
                            }
                            $HTML .= self::showEvents($dataset, false, false, false, $day_num, false, $k);
                        }
                    }
                    $HTML .= "\n\t\t\t\t\t\t</div>\n\t\t\t\t\t </td>";
                    $day_count++;
                    if ($day_count > 7) {
                        $HTML .= "</tr><tr>";
                        $day_count = 1;
                    }
                }
                while ($day_count > 1 && $day_count <= 7) {
                    $HTML .= '<td class="inactive"></td>';
                    $day_count++;
                }
                $HTML .= '</tr>';
            } elseif ($mode == 'week') {
                $alt = $alt ? '' : 'class="alt"';
                $HTML .= "\n\t\t\t\t<tr {$alt}>\n\t\t\t\t\t<td class=\"c_day\"></td>\n\t\t\t\t\t<td class=\"c_day\">'.{$CFG->cal_sun}.'</td>\n\t\t\t\t\t<td class=\"c_day\">'.{$CFG->cal_mon}.'</td>\n\t\t\t\t\t<td class=\"c_day\">'.{$CFG->cal_tue}.'</td>\n\t\t\t\t\t<td class=\"c_day\">'.{$CFG->cal_web}.'</td>\n\t\t\t\t\t<td class=\"c_day\">'.{$CFG->cal_thur}.'</td>\n\t\t\t\t\t<td class=\"c_day\">'.{$CFG->cal_fri}.'</td>\n\t\t\t\t\t<td class=\"c_day\">'.{$CFG->cal_sat}.'</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>";
                foreach ($days_array as $day_num) {
                    $events = self::getEvents(false, false, $day_num);
                    reset($events);
                    $first_key = key($events);
                    $current = $day_num == date('j') && $m == date('n') && $y == date('Y') ? 'current' : '';
                    $HTML .= "\n\t\t\t\t\t<td class=\"{$current}\" onmouseover=\"calCellHover(this)\" onmouseout=\"calCellOut(this)\" onclick=\"calZoomDay({$this->i},'{$CFG->url}',{$CFG->is_tab},{$y},{$m},{$day_num})\">\n\t\t\t\t\t\t<div class=\"wrap\">\n\t\t\t\t\t\t\t<div class=\"day_num\">{$day_num}</div> \n\t\t\t\t\t\t\t" . self::showEvents($events[$first_key], false, false, false, $day_num) . "\n\t\t\t\t\t\t</div>\n\t\t\t\t\t </td>";
                }
                $HTML .= '</tr>';
            } elseif ($mode == 'day') {
                $hour = 0;
                while ($hour <= 23) {
                    $alt = $alt ? '' : 'class="alt"';
                    $HTML .= '
					<tr ' . $alt . '>
						<td class="time" rowspan="2">
							' . date($CFG->default_time_format, strtotime("{$y}-{$m}-{$d} {$hour}:00:00")) . '
						</td>';
                    $HTML .= '<td class="row"></td></tr><tr ' . $alt . '><td class="row"></td></tr>';
                    $hour++;
                }
            }
            $HTML .= "</table>";
        }
        if ($mode == 'day') {
            $events = self::getEvents(false, false, $d);
            if (is_array($events)) {
                if (!$this->print) {
                    $container_width = count($events) * $this->click_width + 2;
                    $HTML .= '<div class="all_floats ' . (!$this->tokenizers ? 'one_float' : '') . '" style="width:' . $container_width . 'px">';
                    $j = 0;
                    foreach ($events as $k => $dataset) {
                        $margin_left = $j * $this->click_width;
                        $HTML .= '
						<div class="float_contain ' . ($this->tokenizers ? 'float_topspace' : '') . '" id="float_contain_' . $k . '" style="margin-left:' . $margin_left . 'px">
							<input type="hidden" id="record_id" value="' . $k . '"/>
							' . self::showEvents($dataset, 1, false, false, $d, 1, $k) . '
						</div>';
                        $j++;
                    }
                    $HTML .= '
					<script type="text/javascript">
						initializeCalFloats();
					</script>';
                    $HTML .= '</div>';
                } else {
                    $i = 0;
                    if ($this->tokenizers) {
                        $tokenizers = $this->tokenizers;
                        $first_key = key($tokenizers);
                        $labels = $tokenizers[$first_key];
                    }
                    foreach ($events as $k => $dataset) {
                        if (is_array($dataset)) {
                            if ($labels) {
                                $HTML .= '<div class="print_caption">' . current($labels) . '</div>';
                            }
                        }
                        $HTML .= $this->printEvents($dataset, false, false, $d, $k);
                        $HTML .= '<div class="page-break"></div>';
                        @next($labels);
                        $i++;
                    }
                    unset($labels);
                }
            }
        }
        $HTML .= '<div class="clear"></div></div></div>';
        if (!$_REQUEST['cal_bypass']) {
            self::show_filters();
            /*
            if ($this->mode == 'day' && !$this->print) {
            	echo '
            	<div class="grid_operations">
            		<span class="button" onclick="saveCalOrder()">'.$CFG->save_icon.' '.$CFG->save_button.'</span>
            		<span class="button" onclick="printCal('.$this->i.')">'.$CFG->print_icon.' '.$CFG->print_button.'</span>
            		<div class="clear"></div>
            	</div>';
            }
            */
        }
        self::show_errors();
        echo $HTML;
    }
Example #12
0
 private function displayItems($tables, $rows = false, $f_id = 0, $level = 1, $p_id = 0)
 {
     global $CFG;
     $pm_method = $CFG->pm_editor ? ' class="pm_method"' : '';
     if ($tables) {
         $parent_id = $rows ? $p_id : $f_id;
         $this->levels[$level][$parent_id] = $parent_id;
         $HTML = '';
         foreach ($tables as $name => $properties) {
             $HTML .= "<ul id=\"mlist_{$this->i}_level_{$level}_{$parent_id}\" class=\"mlist_{$this->i}_level_{$level}\">";
             $properties['url'] = empty($properties['url']) ? $CFG->url : $properties['url'];
             $properties['url_is_tab'] = empty($properties['url_is_tab']) ? $CFG->is_tab : $properties['url_is_tab'];
             if (!empty($properties['parent']) && $f_id == 0) {
                 continue;
             }
             $HTML .= "<input id=\"table\" type=\"hidden\" name=\"table\" value=\"{$name}\" />";
             $HTML .= "<input id=\"enabled\" type=\"hidden\" name=\"enabled\" value=\"{$this->dragdrop}\" />";
             $HTML .= "<input id=\"p_id\" type=\"hidden\" name=\"p_id\" value=\"{$p_id}\" />";
             $HTML .= "<input id=\"f_id\" type=\"hidden\" name=\"f_id\" value=\"{$f_id}\" />";
             if ($CFG->pm_editor) {
                 $HTML .= Form::peLabel($properties['method_id'], 'addTable');
             }
             $table = $rows ? $rows : DB::getCats($name, $f_id);
             if ($table) {
                 foreach ($table as $id => $row) {
                     $hidden = $row['row']['hidden'] == 'Y' ? 'hidden' : '';
                     $HTML .= "<li id=\"{$row['row']['id']}\" class=\"li_{$level} ml_li {$hidden}\">";
                     $HTML .= !empty($row['children']) ? '<div onclick="ml_expand(this)" class="more"></div><div onclick="ml_collapse(this)" class="less"></div>' : '';
                     $HTML .= "<div class=\"ml_item\">";
                     if ($CFG->url == 'edit_tabs' && !empty($row['row']['url'])) {
                         $is_tab = $name == 'admin_tabs' ? '1' : '0';
                         if (User::permission(0, 0, $properties['url'], false, $properties['url_is_tab']) > 1) {
                             $HTML .= '<a class="edit_page" href="index.php?current_url=edit_page&table=' . $name . '&id=' . $row['row']['id'] . '&is_tab=' . $is_tab . '"></a>';
                         }
                     }
                     if (is_array($properties['table_fields'])) {
                         foreach ($properties['table_fields'] as $field) {
                             $value = Grid::detectData($field, $row['row'][$field], $this->fields[$name]);
                             $HTML .= !empty($properties['url']) ? Link::url($properties['url'], $row['row'][$field], "table={$name}&id={$row['row']['id']}&f_id={$row['row']['f_id']}&p_id={$row['row']['p_id']}&action=record&is_tab=" . $properties['url_is_tab'], false, false, $properties['target_elem_id']) : $value;
                         }
                         $del_function = $CFG->url == 'edit_tabs' ? 'deletePage(this)' : 'ml_delete(this)';
                         if (User::permission(0, 0, $properties['url'], false, $properties['url_is_tab']) > 1) {
                             $HTML .= Link::url($properties['url'], false, "table={$name}&id={$row['row']['id']}&f_id={$row['row']['f_id']}&p_id={$row['row']['p_id']}&action=record&is_tab=" . $properties['url_is_tab'], false, false, $properties['target_elem_id'], 'view', false, false, false, false, $CFG->view_hover_caption) . Link::url($properties['url'], false, "table={$name}&id={$row['row']['id']}&f_id={$row['row']['f_id']}&p_id={$row['row']['p_id']}&action=form&is_tab=" . $properties['url_is_tab'], false, false, $properties['target_elem_id'], 'edit', false, false, false, false, $CFG->edit_hover_caption) . "<a href=\"#\" class=\"delete\" title=\"{$CFG->delete_hover_caption}\" onclick=\"{$del_function}\" class=\"button\"></a>";
                         }
                     } else {
                         foreach ($row['row'] as $field) {
                             $HTML .= '<span>' . $field . '</span>';
                         }
                     }
                     $HTML .= $this->row_end_button ? $this->row_end_button : '';
                     if (User::permission(0, 0, $properties['url'], false, $properties['url_is_tab']) > 1 && $accepts_children) {
                         $HTML .= $properties['accept_children'] ? Link::url($properties['url'], '<div class="add_new"></div>' . $CFG->add_new_caption, "table={$name}&f_id={$f_id}&p_id={$p_id}&action=form&is_tab=" . $properties['url_is_tab'], false, false, $properties['target_elem_id']) : '';
                     }
                     $HTML .= '</div>';
                     if (!empty($row['children'])) {
                         $HTML .= MultiList::displayItems(array($name => $properties), $row['children'], false, $level + 1, $id);
                     }
                     foreach ($this->tables as $name1 => $properties1) {
                         if ($properties1['parent'] == $name) {
                             $HTML .= MultiList::displayItems(array($name1 => $properties1), false, $id, $level + 1);
                         }
                     }
                     $HTML .= '</li>';
                 }
             }
             $HTML .= '</ul>';
             $HTML .= "<div class=\"add_elem\">" . Link::url($properties['url'], '<div class="add_new"></div>' . $CFG->add_new_caption, "table={$name}&f_id={$f_id}&p_id={$p_id}&action=form&is_tab=" . $CFG->is_tab, false, false, $properties['target_elem_id']) . "</div>";
         }
         return $HTML;
     }
 }