public static function addBox($content_var, $module, $theme_var = NULL, $theme = NULL) { PHPWS_Core::initModClass('layout', 'Box.php'); if (!isset($theme)) { $theme = $_SESSION['Layout_Settings']->current_theme; } if (!isset($theme_var)) { $mod_theme_var = strtoupper(sprintf('%s_%s', $module, $content_var)); if (!empty($_SESSION['Layout_Settings']->_theme_variables) && in_array($mod_theme_var, $_SESSION['Layout_Settings']->_theme_variables)) { $theme_var = $mod_theme_var; } else { $theme_var = DEFAULT_BOX_VAR; } } $box = new Layout_Box(); $box->setTheme($theme); $box->setContentVar($content_var); $box->setModule($module); $box->setThemeVar($theme_var); $result = $box->save(); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); PHPWS_Core::errorPage(); } Layout::resetBoxes(); }
/** * Moves a box to a new location */ public function move($dest) { if ($dest != 'move_box_up' && $dest != 'move_box_down' && $dest != 'move_box_top' && $dest != 'move_box_bottom' && $dest != 'restore') { $themeVars = $_SESSION['Layout_Settings']->getAllowedVariables(); if (!in_array($dest, $themeVars)) { return PHPWS_Error::get(LAYOUT_BAD_THEME_VAR, 'layout', 'Layout_Box::move', $dest); } $themeVar = $this->theme_var; $this->setThemeVar($dest); $this->setBoxOrder(NULL); $this->save(); $this->reorderBoxes($this->theme, $themeVar); return; } $db = new PHPWS_DB('layout_box'); $db->addWhere('id', $this->id, '!='); $db->addWhere('theme', $this->theme); $db->addWhere('theme_var', $this->theme_var); $db->addOrder('box_order'); $db->setIndexBy('box_order'); $boxes = $db->getObjects('Layout_Box'); if (empty($boxes)) { return NULL; } if (PHPWS_Error::isError($boxes)) { PHPWS_Error::log($boxes); return NULL; } switch ($dest) { case 'restore': $this->kill(); $this->reorderBoxes($this->theme, $this->theme_var); Layout::resetBoxes(); return; break; case 'move_box_up': if ($this->box_order == 1) { $this->move('move_box_bottom'); return; } else { $old_box =& $boxes[$this->box_order - 1]; $old_box->box_order++; $this->box_order--; if (!PHPWS_Error::logIfError($old_box->save())) { PHPWS_Error::logIfError($this->save()); } return; } break; case 'move_box_down': if ($this->box_order == count($boxes) + 1) { $this->move('move_box_top'); return; } else { $old_box =& $boxes[$this->box_order + 1]; $old_box->box_order--; $this->box_order++; if (!PHPWS_Error::logIfError($old_box->save())) { PHPWS_Error::logIfError($this->save()); } return; } break; case 'move_box_top': $this->box_order = 1; $this->save(); $count = 2; break; case 'move_box_bottom': $this->box_order = count($boxes) + 1; $this->save(); $count = 1; break; } foreach ($boxes as $box) { $box->box_order = $count; $box->save(); $count++; } }
/** * Receives the post results of the box change form. */ public static function moveBox() { PHPWS_Core::initModClass('layout', 'Box.php'); $box = new Layout_Box($_GET['box_source']); $result = $box->move($_GET['box_dest']); if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); Layout::add('An unexpected error occurred when trying to save the new box position.'); return; } Layout::resetBoxes(); return true; }