public static function get_installed_applets_html() { $colors = Base_DashboardCommon::get_available_colors(); $app_cap = ModuleManager::call_common_methods('applet_caption'); asort($app_cap); $app_info = ModuleManager::call_common_methods('applet_info'); $html = ''; foreach ($app_cap as $name => $cap) { if (!$cap) { continue; } $th = Base_ThemeCommon::init_smarty(); $id = str_replace('_', '-', $name); if (!isset($app_info[$name])) { $app_info[$name] = ''; } $th->assign('content', '<div class="content" style="padding:4px;" id="dashboard_applet_content_' . $id . '">' . $app_info[$name] . '</div>'); $th->assign('handle_class', 'handle'); $th->assign('caption', $cap); $th->assign('color', $colors[0]['class']); $remove_button = Base_DashboardCommon::get_remove_applet_button($id, false); $th->assign('remove', $remove_button); $th->assign('__link', array('remove' => Base_ThemeCommon::parse_links('remove', $remove_button))); //print('<xmp>'.self::get_remove_applet_button(null, false).'</xmp><br>'); $th->assign('actions', array()); $th->assign('config_mode', true); $html .= '<div class="applet" searchkey="' . strtolower($cap ? $cap : $name) . ';' . strtolower($app_info[$name]) . '" id="ab_item_' . 'new_' . $id . '">'; ob_start(); Base_ThemeCommon::display_smarty($th, 'Base_Dashboard', 'default'); $html .= ob_get_clean(); $html .= '</div>'; } return $html; }
$val = null; } else { $table = 'base_dashboard_applets'; $val = $user; } foreach ($x['ab_item'] as $pos => $id) { if (is_numeric($id)) { $vals = array($pos, $_POST['col'], $id); if ($val) { $vals[] = $val; } DB::Execute('UPDATE ' . $table . ' SET pos=%d, col=%d WHERE id=%d' . ($val ? ' AND user_login_id=%d' : ''), $vals); } elseif (strpos($id, 'new_') === 0) { $id = substr($id, 4); $cleanId = str_replace('-', '_', $id); $vals = array($cleanId, $tab, $_POST['col'], $pos); if ($val) { $vals[] = $val; } DB::Execute('INSERT INTO ' . $table . '(module_name,tab,col,pos' . ($val ? ',user_login_id' : '') . ') VALUES (%s,%d,%d,%d' . ($val ? ',%d' : '') . ')', $vals); $new_id = DB::Insert_ID('base_dashboard_applets', 'id'); print 'if(jq("#copy_ab_item_new_' . $id . '").length>0){' . 'jq("#copy_dashboard_remove_applet_' . $id . '").attr("onclick","if(confirm(\'' . __('Delete this applet?') . '\'))remove_applet(' . $new_id . ',' . ($default ? 1 : 0) . ');")' . '.show("fade",300);' . 'jq("#copy_dashboard_applet_content_' . $id . '").hide("blind",300);' . 'jq("#copy_dashboard_remove_applet_' . $id . '").attr("id","dashboard_remove_applet_' . $new_id . '");' . 'jq("#copy_dashboard_applet_content_' . $id . '").attr("id","dashboard_applet_content_' . $new_id . '");' . 'jq("#copy_ab_item_new_' . $id . '").attr("id","ab_item_' . $new_id . '");' . '}'; } } } elseif ($_POST['col'] == 'new') { foreach ($x['ab_item'] as $pos => $id) { if (is_numeric($id)) { Base_DashboardCommon::remove_applet($id, $default); } } }
public function configure_applet($id, $mod, &$ok = null) { $default_dash = $this->get_module_variable('default'); if (!$default_dash && !Base_DashboardCommon::has_permission_to_manage_applets()) { return; } if ($this->is_back()) { $ok = false; return false; } $sett_fn = array($mod . 'Common', 'applet_settings'); $is_conf = is_callable($sett_fn); $fc = $this->get_module_variable('first_conf'); if (!$is_conf && $fc) { $ok = true; return false; } $f = $this->init_module(Libs_QuickForm::module_name(), __('Saving settings'), 'settings'); $caption = call_user_func(array($mod . 'Common', 'applet_caption')); if ($is_conf) { $f->addElement('header', null, __('%s settings', array($caption))); $menu = call_user_func($sett_fn); if (is_array($menu)) { $this->add_module_settings_to_form($menu, $f, $id, $mod); } else { trigger_error('Invalid applet settings function: ' . $mod, E_USER_ERROR); } } $f->addElement('header', null, $caption . ' ' . __('display settings')); $color = Base_DashboardCommon::get_available_colors(); $color[0] = __('Default') . ': ' . $color[0]['label']; for ($k = 1; $k < count($color); $k++) { $color[$k] = '• ' . $color[$k]['label']; } $f->addElement('select', '__color', __('Color'), $color, array('style' => 'width: 100%;')); $table_tabs = 'base_dashboard_' . ($default_dash ? 'default_' : '') . 'tabs'; $table_applets = 'base_dashboard_' . ($default_dash ? 'default_' : '') . 'applets'; $tabs = DB::GetAssoc('SELECT id,name FROM ' . $table_tabs . ($default_dash ? '' : ' WHERE user_login_id=' . Base_AclCommon::get_user())); $f->addElement('select', '__tab', __('Tab'), $tabs); $dfs = DB::GetRow('SELECT tab,color FROM ' . $table_applets . ' WHERE id=%d', array($id)); $f->setDefaults(array('__tab' => $dfs['tab'], '__color' => $dfs['color'])); if ($f->validate()) { //$f->process(array(& $this, 'submit_settings')); $submited = $f->exportValues(); DB::Execute('UPDATE ' . $table_applets . ' SET tab=%d WHERE id=%d', array($submited['__tab'], $id)); DB::Execute('UPDATE ' . $table_applets . ' SET color=%d WHERE id=%d', array($submited['__color'], $id)); $defaults = $this->get_default_values($mod); $old = $this->get_values($id, $mod); foreach ($defaults as $name => $def_value) { if (!isset($submited[$name])) { $submited[$name] = 0; } if ($submited[$name] != $old[$name]) { if ($this->get_module_variable('default')) { if ($submited[$name] == $def_value) { DB::Execute('DELETE FROM base_dashboard_default_settings WHERE applet_id=%d AND name=%s', array($id, $name)); } else { DB::Replace('base_dashboard_default_settings', array('applet_id' => $id, 'name' => $name, 'value' => $submited[$name]), array('applet_id', 'name'), true); } } else { if ($submited[$name] == $def_value) { DB::Execute('DELETE FROM base_dashboard_settings WHERE applet_id=%d AND name=%s', array($id, $name)); } else { DB::Replace('base_dashboard_settings', array('applet_id' => $id, 'name' => $name, 'value' => $submited[$name]), array('applet_id', 'name'), true); } } } } $ok = true; self::$settings_cache = null; return false; } $ok = null; $f->display(); Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href()); Base_ActionBarCommon::add('save', __('Save'), $f->get_submit_form_href()); Base_ActionBarCommon::add('settings', __('Restore Defaults'), 'onClick="' . $this->set_default_js . '" href="javascript:void(0)"'); return true; }