Copyright 2004-2007 Andrew Coleman Copyright 2007-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Andrew Coleman (mercury@appisolutions.net)
Example #1
0
 /**
  * Add additional items to the sidebar.
  *
  * @param Horde_View_Sidebar $sidebar  The sidebar object.
  */
 public function sidebar($sidebar)
 {
     $perms = $GLOBALS['injector']->getInstance('Horde_Core_Perms');
     if (Sesha::isAdmin(Horde_Perms::READ) || $perms->hasPermission('sesha:addStock', $GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
         $sidebar->addNewButton(_("_Add Stock"), Horde::url('stock.php')->add('actionId', 'add_stock'));
     }
 }
Example #2
0
File: List.php Project: horde/horde
 /**
  * Returns the items which match the category or search criteria.
  */
 protected function stock($filters = array())
 {
     $driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
     // Get the inventory
     $stock = $driver->findStock($filters);
     $isAdminEdit = Sesha::isAdmin(Horde_Perms::EDIT);
     $itemEditImg = Horde::img('edit.png', _("Edit Item"));
     $isAdminDelete = Sesha::isAdmin(Horde_Perms::DELETE);
     $adminDeleteImg = Horde::img('delete.png', _("Delete Item"));
     $stock_url = Horde::url('stock.php');
     $items = array();
     foreach ($stock as $item) {
         $url = $stock_url->add('stock_id', $item->stock_id);
         $columns = array();
         // icons
         $icons = '';
         if ($isAdminEdit) {
             $icons .= $url->copy()->add('actionId', 'update_stock')->link(array('title' => _("Edit Item"))) . $itemEditImg . '</a>';
         }
         if ($isAdminDelete) {
             $icons .= $url->copy()->add('actionId', 'remove_stock')->link(array('title' => _("Delete Item"))) . $adminDeleteImg . '</a>';
         }
         $columns[] = array('class' => ' class="nowrap"', 'column' => $icons);
         // stock_id
         $columns[] = array('class' => '', 'column' => $url->copy()->add('actionId', 'view_stock')->link(array('title' => _("View Item"))) . htmlspecialchars($item->stock_id) . '</a>');
         // name
         $columns[] = array('class' => '', 'column' => $url->copy()->add('actionId', 'view_stock')->link(array('title' => _("View Item"))) . htmlspecialchars($item->stock_name) . '</a>');
         // properties
         foreach ($this->shownProperties as $property) {
             $value = $item->getValue($property);
             $columns[] = array('class' => '', 'column' => $value ? htmlspecialchars($value->getDataValue()) : '&nbsp;');
         }
         // note
         $columns[] = array('class' => '', 'column' => $item->note ? htmlspecialchars($item->note) : '&nbsp;');
         $items[] = array('columns' => $columns);
     }
     return $items;
 }
Example #3
0
$topbar->searchAction = new Horde_Url('list.php');
$topbar->searchLabel = _("Stock ID");
$topbar->searchIcon = Horde_Themes::img('search-topbar.png');
$perms = $GLOBALS['injector']->getInstance('Horde_Perms');
$sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
$vars = Horde_Variables::getDefaultVariables();
$category_id = $vars->get('category_id');
$property_id = $vars->get('property_id');
$actionID = $vars->get('actionID');
// Admin actions.
$baseUrl = $registry->get('webroot', 'sesha');
$adminurl = Horde::url('admin.php', true);
$tabs = new Horde_Core_Ui_Tabs('actionID', $vars);
$tabs->addTab(_("Manage Categories"), $adminurl, 'list_categories');
$tabs->addTab(_("Manage Properties"), $adminurl, 'list_properties');
if (!Sesha::isAdmin(Horde_Perms::DELETE)) {
    $notification->push(_("You are no administrator"), 'horde.warning');
    header('Location: ' . Horde::url('list.php', true));
    exit;
}
/* Run through the action handlers. */
switch ($actionID) {
    case 'add_category':
        $url = Horde::url('admin.php')->add('actionID', 'list_categories');
        $title = _("Add a category");
        $vars->set('actionID', $actionID);
        $renderer = new Horde_Form_Renderer();
        $form = new Sesha_Form_Category($vars);
        if ($form->validate($vars)) {
            $form->getInfo($vars, $info);
            // Save category details.
Example #4
0
 /**
  * The default constructor for the StockForm class.
  *
  * @param Horde_Variables $vars  The default variables to use.
  */
 public function __construct($vars)
 {
     parent::__construct($vars);
     $sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
     // Buttons and hidden configuration
     $this->setButtons(_("Save Item"));
     $this->addHidden('', 'actionId', 'text', true);
     // Prepare the categories
     $cat = array();
     $categories = $sesha_driver->getCategories();
     foreach ($categories as $c) {
         $cat[$c->category_id] = $c->category;
     }
     // Get the list of selected categories
     $categoryIds = array();
     $t = $vars->get('category_id');
     if (!is_array($t)) {
         $t = array($t);
     }
     $categoryIds = array_merge($categoryIds, $t);
     // The stock ID should only be editable if you are adding a new item;
     // otherwise let the user know what the stock_id is, and then make a
     // read-only required hidden variable
     if ($vars->get('actionId') == 'add_stock') {
         $this->addVariable(_("Stock ID"), 'stock_id', 'int', false, false);
     } else {
         $this->addVariable(_("Stock ID"), 'stock_id', 'int', false, true);
         $this->addHidden('', 'stock_id', 'int', true, true);
     }
     // Basic variables for any stock item
     $this->addVariable(_("Name"), 'stock_name', 'text', false, false);
     if (!count($cat)) {
         $fieldtype = 'invalid';
         $cat = _("No categories are currently configured. Click \"Administration\" on the left to add some.");
     } else {
         $fieldtype = 'multienum';
     }
     $categoryVar = $this->addVariable(_("Category"), 'category_id', $fieldtype, true, false, null, array($cat));
     // Set the variables already stored in the Driver, if applicable
     try {
         $properties = $sesha_driver->getPropertiesForCategories($categoryIds);
     } catch (Sesha_Exception $e) {
         throw new Sesha_Exception($e);
     }
     foreach ($properties as $property) {
         $fieldname = 'property[' . $property->property_id . ']';
         $fieldtitle = $property->property;
         $fielddesc = $property->description;
         if (!empty($property->unit)) {
             if (!empty($fielddesc)) {
                 $fielddesc .= ' -- ';
             }
             $fielddesc .= _("Unit: ") . $property->unit;
         }
         $fieldtype = $property->datatype;
         $fieldparams = array();
         if (is_array($property->parameters)) {
             $fieldparams = $property->parameters;
             if (in_array($fieldtype, array('link', 'enum', 'multienum', 'mlenum', 'radio', 'set', 'sorter'))) {
                 $fieldparams->values = Sesha::getStringlistArray($fieldparams->values);
             }
         }
         $this->addVariable($fieldtitle, $fieldname, $fieldtype, false, false, $fielddesc, $fieldparams);
     }
     $this->addVariable(_("Note"), 'note', 'longtext', false);
     // Default action
     $action = Horde_Form_Action::factory('submit');
     $categoryVar->setAction($action);
     $categoryVar->setOption('trackchange', true);
 }