OSDN Git Service

add ACS webapp, sql, htdocs
[acs/acs.git] / webapp / lib / SimpleViewEx.class.php
diff --git a/webapp/lib/SimpleViewEx.class.php b/webapp/lib/SimpleViewEx.class.php
new file mode 100644 (file)
index 0000000..0705092
--- /dev/null
@@ -0,0 +1,418 @@
+<?php
+require_once(MO_PEAR_DIR . '/Config.php');
+require_once(MO_PEAR_DIR . '/HTML/menu.php');
+require_once(MO_PEAR_DIR . '/HTML/Menu/DirectRenderer.php');
+ini_set("display_errors", 0);
+ini_set("error_reporting", false);
+require_once(MO_PEAR_DIR . '/HTML/QuickForm/Renderer/ArraySmarty.php');
+require_once(MO_PEAR_DIR . '/Pager/Pager.php');
+ini_restore("error_reporting");
+ini_restore("display_errors");
+
+/**
+ * View¤Î³ÈÄ¥¥¯¥é¥¹
+ * @access public
+ * @package webapp/lib
+ * @category view
+ * @author Tsutomu Wakuda <wakuda@withit.co.jp>
+ * @sourcefile
+ *
+ */
+abstract class SimpleViewEx extends SmartyView
+{
+       /**
+        * Controller¥ª¥Ö¥¸¥§¥¯¥È 
+        * @var Controller
+        */
+       protected $controller = '';
+       
+       /**
+        * Request¥ª¥Ö¥¸¥§¥¯¥È
+        * @var Request
+        */
+       protected $request = '';
+       
+       /* user¥ª¥Ö¥¸¥§¥¯¥È */
+       private $user = '';
+       
+       /* HTML_QuickForm¤ÎSmarty¥ì¥ó¥À¥é */
+       private $quickformSmarty = '';
+       
+       /* ¥á¥Ã¥»¡¼¥¸¥Ç¡¼¥¿ */
+       private $messages = '';
+
+       /* ¥Ú¡¼¥¸Ì¾ */
+       private $pageName = 'page1';
+       
+       /* ²èÌÌÁ«°ÜÀè¤Î¥â¥¸¥å¡¼¥ë̾ */
+       private $moduleName = '';
+
+       /* ²èÌÌÁ«°ÜÀè¤Î¥¢¥¯¥·¥ç¥ó̾ */
+       private $actionName = '';
+
+       var $css_file_array = array();
+       var $js_file_array = array();
+       
+       /**
+        * ½é´ü½èÍý
+        * @access public
+        * @param Object $contextt context
+        * @return boolean ½èÍý·ë²Ì
+        */
+       public function initialize ($context)
+       {
+               parent::initialize($context);
+
+               /* ½é´üÃͤò¥»¥Ã¥È¤¹¤ë */
+               $this->controller = $context->getController();
+               $this->request = $context->getRequest();
+               $this->user = $context->getUser();
+
+               $this->moduleName = $context->getModuleName();
+               $this->actionName = $context->getActionName();
+               $this->messages = &CommonMessages::getInstance();
+               
+               /* ¥Õ¥©¡¼¥àÅÐÏ¿¥ê¥¹¥È¤Î¥Õ¥©¡¼¥à¤òsmarty¤Ë¤¹¤Ù¤Æ¥»¥Ã¥È¤¹¤ë */
+               $o_smarty = &$this->getEngine();
+               $o_smarty->register_object("style", $this, array("request", "checkErrorElement"));
+               $this->quickformSmarty = 
+                       new HTML_QuickForm_Renderer_ArraySmarty($this->getEngine());
+               $formList = $this->request->getAttribute('formList');
+               foreach ($formList as $formName) {
+                       $this->setForm($formName);
+               }
+
+               /* ¥á¥Ã¥»¡¼¥¸¤òsmarty¤Ë¥»¥Ã¥È¤¹¤ë */
+               if ($this->request->hasAttribute('messages')) {
+                       $messages = &$this->request->getAttribute('messages');
+                       $messages = array_unique($messages);
+                       $this->setAttributeByRef('messages', $messages);
+               }               
+               /* ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤òsmarty¤Ë¥»¥Ã¥È¤¹¤ë */
+               if ($this->request->hasErrors()) {
+                       $errors = &$this->request->getErrors();
+                       $errors = array_unique($errors);
+                       $this->setAttributeByRef('errors', $errors);
+               }
+
+               
+               // ¶¦Ä̤ΠCSS ¤ò¥»¥Ã¥È
+               array_push($this->css_file_array, ACS_SELECTION_CSS_DIR . ACS_DEFAULT_SELECTION_CSS_FILE);
+               $this->setAttribute('include_css_array', $this->css_file_array);
+
+               // ¶¦Ä̤ΠJS ¤ò¥»¥Ã¥È
+               array_push($this->js_file_array, ACS_JS_DIR . ACS_COMMON_JS);
+               $this->setAttribute('include_script_array', $this->js_file_array);
+               
+               return true;
+       }
+
+       /**
+        * ²èÌÌID¤ò¥»¥Ã¥È¤¹¤ë
+        * ²èÌÌID¤ËɳÉÕ¤¯²èÌÌ¥¿¥¤¥È¥ë¤È¥â¥¸¥å¡¼¥ë̾¤È¥¢¥¯¥·¥ç¥ó̾¤òsmarty¤Ë¥»¥Ã¥È¤¹¤ë
+        * @access public
+        * @param string $id ²èÌÌID
+        */
+       public function setScreenId($id)
+       {
+               /* Decorator¥Æ¥ó¥×¥ì¡¼¥È¤ò¥»¥Ã¥È¤¹¤ë */
+               $this->setDecoratorDirectory(MO_TEMPLATE_DIR);
+               $this->setDecoratorTemplate(MO_SIMPLE_TEMPLATE_FILE);
+
+               // ¥¹¥¯¥ê¡¼¥ó¥¿¥¤¥È¥ë¤ò¼èÆÀ¤¹¤ë
+               $title = '';
+               $screenName = '';
+               $screenNameList = MO_CONFIG_DIR . '/' . S4_SCREEN_NAME_LIST;
+               $moduleName = '';
+               $actionName = '';
+               if (file_exists($screenNameList)) {
+                       $config = new Config();
+                       $container = $config->parseConfig($screenNameList, 'inifile');
+                       $child=$container->searchPath(array('ScreenName'));
+                       $screenList = $child->toArray();
+                       if (isset($screenList['ScreenName'][$id])) {
+                               list ($screenName, $moduleName, $actionName) = explode(',', $screenList['ScreenName'][$id]);
+                       }
+                       // ¥¿¥¤¥È¥ë¥Ð¡¼¤Ë²èÌÌ¥¿¥¤¥È¥ë¤ò¥»¥Ã¥È¤¹¤ë
+                       $title = $screenName;
+               }
+               
+               // ²èÌÌ¥¿¥¤¥È¥ë¤òÀßÄꤹ¤ë
+               $this->setAttribute('title', $title);
+               $this->setAttribute('screen_name', $screenName);
+       }
+       
+       /**
+        * ¥Õ¥©¡¼¥à¤òÅÐÏ¿¤¹¤ë
+        * @access public
+        * @param String $formName ¥Õ¥©¡¼¥à̾ 
+        * @param Object $form ¥Õ¥©¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È
+        */
+       public function setForm($formName = '', $form = null)
+       {
+               /* ½é´üÃͤò¥»¥Ã¥È¤¹¤ë */
+               if (empty($form)) {
+                       $form = &$this->request->getAttribute($formName);
+                       if (empty($form)) {
+                               throw new ApplicationException('Not found form is "' . $formName . '."');
+                       }
+               }
+               
+               /* ¥¨¥é¡¼¹àÌܤÎÇØ·Ê¿§¤òÀßÄꤹ¤ë */
+               if ($this->request->hasErrors()) {
+                       $errorNames = &$this->request->getErrorNames();
+                       $errorNames = array_unique($errorNames);
+                       foreach ($errorNames as $name) {
+                               if ($form->elementExists($name)) {
+                                       $element = &$form->getElement($name);
+                                       $this->_setErrorAttribute($element);
+                               }
+                       }
+               }
+               
+               /* ¥Õ¥©¡¼¥à¤òsmarty¤Ë¥»¥Ã¥È¤¹¤ë */
+               $form->accept($this->quickformSmarty);
+               $this->setAttribute($formName, $this->quickformSmarty->toArray());
+       }
+
+       /**
+        * ¥¨¥é¡¼¹àÌܤÎÇØ·Ê¿§¤òÀßÄꤹ¤ë
+        * ¡ÊQuickForm¤Î¹àÌܤËÂФ·¤Æ¡¢ÇØ·Ê¿§¤òÀßÄꤹ¤ë¡Ë
+        * @access public
+        * @param HTML_QuickForm_element $element ¥¨¥é¡¼¹àÌÜ
+        */
+       private function _setErrorAttribute(&$element)
+       {
+               if ('group' == $element->getType()) {
+                       $elements = $element->getElements();
+                       foreach ($elements as $value) {
+                               $this->_setErrorAttribute($value);
+                       }
+               } else {
+                       $attr = $element->getAttributes();
+                       $attr['style'] = S4_ERROR_COLUMN_COLOR;
+                       $element->setAttributes($attr);
+               }
+       }
+       
+       /**
+        * ¥¨¥é¡¼¹àÌܤòȽÃǤ·¡¢HTML¤Îstyle¥×¥í¥Ñ¥Æ¥£¤òÊֵѤ¹¤ë
+        * Smarty¤«¤é¥³¡¼¥ë¤µ¤ì¤ëfunction¤Î¤¿¤á¡¢$params¤Ë¤Ï¡¢Ï¢ÁÛÇÛÎó·Á¼°¤Ç
+        * $params['name']¤Ë¥Á¥§¥Ã¥¯¤¹¤ë¹àÌÜ̾¤ò¥»¥Ã¥È¤¹¤ë
+        * ¢¨setErrorMesseage¤ÎÂèÆó°ú¿ô¤È¡¢HTML¤Îname¤ò°ìÃפµ¤»¤ë¤³¤È
+        * @param array $params Smarty¥Ñ¥é¥á¡¼¥¿
+        * @param Smarty &$o_smarty Smarty¥ª¥Ö¥¸¥§¥¯¥È
+        */
+       public function checkErrorElement($params, &$o_smarty)
+       {
+               $retVal = '';
+               
+               /* ¥¨¥é¡¼¹àÌܤÎÇØ·Ê¿§¤òÀßÄꤹ¤ë */
+               if ($this->request->hasError($params['name'])) {
+                       $retVal = sprintf('style="%s"', S4_ERROR_COLUMN_COLOR);
+               }
+               
+               return $retVal;
+       }
+       
+       /**
+        * ¶¦ÄÌ¥á¥Ã¥»¡¼¥¸¤ò¼èÆÀ¤¹¤ë
+        * ¥Ñ¥é¥á¡¼¥¿¤ò°ú¤­ÅϤ¹¤È¡¢¥á¥Ã¥»¡¼¥¸¤Î%s¤Ë¥Ñ¥é¥á¡¼¥¿¤ò¥»¥Ã¥È¤·ÊֵѤ·¤Þ¤¹¡£
+        * @access public
+        * @param string $id ¥á¥Ã¥»¡¼¥¸ID
+        * @param object $args ¶¦ÄÌ¥á¥Ã¥»¡¼¥¸¤Î¥Ñ¥é¥á¡¼¥¿(ÇÛÎó¤Þ¤¿¤Ï¡¢ÊÑ¿ô)
+        * @return string ¶¦ÄÌ¥á¥Ã¥»¡¼¥¸
+        */
+       public function getMessage($id, $args = null)
+       {
+               /* ¥á¥Ã¥»¡¼¥¸¼èÆÀ */
+               $msg = $this->messages->getParameter($id);
+               if (empty($msg)) {
+                       throw new ApplicationException("Not found message! id=$id");
+               }
+               
+               /* ¥Ñ¥é¥á¡¼¥¿¥»¥Ã¥È */
+               if (is_array($args)) {
+                       $msg = vsprintf($msg, $args);
+               } else {
+                       $msg = sprintf($msg, $args);
+               }
+               
+               return $msg;
+       }
+
+       /**
+        * ¥Ú¡¼¥¸¥Ç¡¼¥¿(1¥Ú¡¼¥¸Ê¬)¤ò¥»¥Ã¥È¤¹¤ë
+        * ¡¦¥Ú¡¼¥¸¥Ç¡¼¥¿(1¥Ú¡¼¥¸Ê¬)¤ò¼õ¤±¼è¤ê¡¢smarty¤Ëpager¤È¥Ú¡¼¥¸¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤¹¤ë¡£
+        *  ¤Ê¤ª¡¢¥Ú¡¼¥¸¥ó¥°¤ÎºÝ¤Î²èÌÌÁ«°ÜÀè¤Ï¡¢°ú¿ô¤Ç»ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤Ç¤¢¤ë¡£
+        * ¡¦¥¢¥¯¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢²èÌÌID¤ËɳÉÕ¤¯¥¢¥¯¥·¥ç¥ó¤¬¥Ç¥Õ¥©¥ë¥È¤È¤Ê¤ë¡£
+        * ¡¦Pager¤ËÊÝ»ý¤µ¤»¤ë¹àÌܤ¬¤¢¤ë¾ì¹ç¤Ï¡¢$extraVars¤Ë¥«¥é¥à̾¤ò¥»¥Ã¥È¤¹¤ë¡£
+        * ¡¦Pager¤ËÊÝ»ý¤µ¤»¤¿¤¯¤Ê¤¤¹àÌܤ¬¤¢¤ë¾ì¹ç¤Ï¡¢$excludeVars¤Ë¥«¥é¥à̾¤ò¥»¥Ã¥È¤¹¤ë¡£
+        * @access public
+        * @param array $itemData ¥Ú¡¼¥¸¥ó¥°¤Î¥¢¥¤¥Æ¥àÇÛÎó¥Ç¡¼¥¿
+        * @param int $totalItems Á´¥Ú¡¼¥¸¤Î¥¢¥¤¥Æ¥à¹ç·×
+        * @param int $perPage ¥Ú¡¼¥¸¤¢¤¿¤ê¤Î¥¢¥¤¥Æ¥à¿ô
+        * @param string $pageName ¥Ú¡¼¥¸Ì¾
+        * @param string $moduleName ¥â¥¸¥å¡¼¥ë̾
+        * @param string $actionName ¥¢¥¯¥·¥ç¥ó̾
+        * @param array $extraVars Pager¤ËÊÝ»ý¤µ¤»¤ë¹àÌÜ(¥«¥é¥à̾)
+        * @param array $excludeVars Pager¤ËÊÝ»ý¤µ¤»¤Ê¤¤¹àÌÜ(¥«¥é¥à̾)
+        */
+       public function setPageTotalItems($itemData = null, $perPage = 30, $totalItems = null, $pageName = null, 
+               $moduleName = null, $actionName = null, $extraVars = array(), $excludeVars = array())
+       {
+               /* ½é´üÃͤò¥»¥Ã¥È¤¹¤ë */
+               if (empty($pageName)) {
+                       $pageName = $this->getPageName();
+               }
+               if (empty($moduleName)) {
+                       $moduleName = $this->moduleName;
+               }
+               if (empty($actionName)) {
+                       $actionName = $this->actionName;
+               }
+               if (empty($perPage)) {
+                       $perPage = 30;
+               }
+               /* ²èÌÌÁ«°ÜÀè¤ò¼èÆÀ¤¹¤ë */
+               $parameters['module'] = $moduleName;
+               $parameters['action'] = $actionName;
+               
+               $url = $this->controller->genURL(null, $parameters);
+
+               /* ¥Ú¡¼¥¸¤òÀ¸À®¤¹¤ë */
+               $params = array("totalItems" => $totalItems,
+                       "perPage" => $perPage,
+                       "mode" => "Jumping",
+                       "httpMethod" => "POST",
+                       "urlVar" => $pageName,
+                       "fixFileName" => false,
+                       "path" => "",
+                       "fileName" => $url,
+                       "prevImg" => '&lt;&lt;',
+                       "nextImg" => '&gt;&gt;',
+                       "altFirst" => "ºÇ½é¥Ú¡¼¥¸",
+                       "altPrev" => "Á°¥Ú¡¼¥¸",
+                       "altNext" => "¼¡¥Ú¡¼¥¸",
+                       "altLast" => "ºÇ½ª¥Ú¡¼¥¸",
+                       "firstPagePre" => "{",
+                       "firstPageText" => "ºÇ½é",
+                       "firstPagePost" => "}",
+                       "lastPagePre" => "{",
+                       "lastPageText" => "ºÇ½ª",
+                       "lastPagePost" => "}",
+                       "extraVars" => $extraVars,
+                       "excludeVars" => $excludeVars);
+               $pager = Pager::factory($params);
+               
+               /* ¥Ú¡¼¥¸¤òsmarty¤Ë¥»¥Ã¥È¤¹¤ë */
+               $this->setAttribute($pageName, $pager);
+               if (count($itemData) > 0) {
+                       $this->setAttribute($pageName . '_data', $itemData);
+               } else {
+                       $this->setAttribute($pageName . '_data', $this->getMessage("MC-006"));
+               }
+       }
+       
+       /**
+        * ¥Ú¡¼¥¸¥Ç¡¼¥¿(Á´¤Æ¤Î¥Ú¡¼¥¸)¤ò¥»¥Ã¥È¤¹¤ë
+        * ¡¦¥Ú¡¼¥¸¥Ç¡¼¥¿(Á´¤Æ¤Î¥Ú¡¼¥¸)¤ò¼õ¤±¼è¤ê¡¢smarty¤Ëpager¤È¥Ú¡¼¥¸¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤¹¤ë¡£
+        *  ¤Ê¤ª¡¢¥Ú¡¼¥¸¥ó¥°¤ÎºÝ¤Î²èÌÌÁ«°ÜÀè¤Ï¡¢°ú¿ô¤Ç»ØÄꤵ¤ì¤¿¥¢¥¯¥·¥ç¥ó¤Ç¤¢¤ë¡£
+        * ¡¦¥¢¥¯¥·¥ç¥ó¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢²èÌÌID¤ËɳÉÕ¤¯¥¢¥¯¥·¥ç¥ó¤¬¥Ç¥Õ¥©¥ë¥È¤È¤Ê¤ë¡£
+        * ¡¦Pager¤ËÊÝ»ý¤µ¤»¤ë¹àÌܤ¬¤¢¤ë¾ì¹ç¤Ï¡¢$extraVars¤Ë¥«¥é¥à̾¤ò¥»¥Ã¥È¤¹¤ë¡£
+        * ¡¦Pager¤ËÊÝ»ý¤µ¤»¤¿¤¯¤Ê¤¤¹àÌܤ¬¤¢¤ë¾ì¹ç¤Ï¡¢$excludeVars¤Ë¥«¥é¥à̾¤ò¥»¥Ã¥È¤¹¤ë¡£
+        * @access public
+        * @param array $itemData ¥Ú¡¼¥¸¥ó¥°¤Î¥¢¥¤¥Æ¥àÇÛÎó¥Ç¡¼¥¿
+        * @param int $perPage ¥Ú¡¼¥¸¤¢¤¿¤ê¤Î¥¢¥¤¥Æ¥à¿ô
+        * @param string $pageName ¥Ú¡¼¥¸Ì¾
+        * @param string $moduleName ¥â¥¸¥å¡¼¥ë̾
+        * @param string $actionName ¥¢¥¯¥·¥ç¥ó̾
+        * @param array $extraVars Pager¤ËÊÝ»ý¤µ¤»¤ë¹àÌÜ(¥«¥é¥à̾)
+        * @param array $excludeVars Pager¤ËÊÝ»ý¤µ¤»¤Ê¤¤¹àÌÜ(¥«¥é¥à̾)
+        */
+       public function setPageItemData($itemData = null, $perPage = 30, $pageName = null, 
+               $moduleName = null, $actionName = null, $extraVars = array(), $excludeVars = array())
+       {
+               /* ½é´üÃͤò¥»¥Ã¥È¤¹¤ë */
+               if (empty($pageName)) {
+                       $pageName = $this->getPageName();
+               }
+               if (empty($moduleName)) {
+                       $moduleName = $this->moduleName;
+               }
+               if (empty($actionName)) {
+                       $actionName = $this->actionName;
+               }
+               if (empty($perPage)) {
+                       $perPage = 30;
+               }
+               
+               /* ²èÌÌÁ«°ÜÀè¤òÀßÄꤹ¤ë */
+               $parameters['module'] = $moduleName;
+               $parameters['action'] = $actionName;
+               
+               $url = $this->controller->genURL(null, $parameters);
+
+               /* ¥Ú¡¼¥¸¤òÀ¸À®¤¹¤ë */
+               $params = array ("itemData" => $itemData,
+                       "perPage" => $perPage,
+                       "mode" => "Jumping",
+                       "httpMethod" => "POST",
+                       "urlVar" => $pageName,
+                       "fixFileName" => false,
+                       "path" => "",
+                       "fileName" => $url,
+                       "prevImg" => '&lt;&lt;',
+                       "nextImg" => '&gt;&gt;',
+                       "altFirst" => "ºÇ½é¥Ú¡¼¥¸",
+                       "altPrev" => "Á°¥Ú¡¼¥¸",
+                       "altNext" => "¼¡¥Ú¡¼¥¸",
+                       "altLast" => "ºÇ½ª¥Ú¡¼¥¸",
+                       "firstPagePre" => "{",
+                       "firstPageText" => "ºÇ½é",
+                       "firstPagePost" => "}",
+                       "lastPagePre" => "{",
+                       "lastPageText" => "ºÇ½ª",
+                       "lastPagePost" => "}",
+                       "extraVars" => $extraVars,
+                       "excludeVars" => $excludeVars);
+               $pager = Pager::factory($params);
+               
+               /* ¥Ú¡¼¥¸¤òsmarty¤Ë¥»¥Ã¥È¤¹¤ë */
+               $pageData = array();
+               foreach ($pager->getPageData() as $lineData) {
+                       $pageData[] = $lineData;
+               }
+               $this->setAttribute($pageName, $pager);
+               if (count($pageData) > 0) {
+                       $this->setAttribute($pageName . '_data', $pageData);
+               } else {
+                       $this->setAttribute($pageName . '_data', $this->getMessage("MC-006"));
+               }
+       }
+       
+       /**
+        * ¥Ú¡¼¥¸Ì¾¤ò¼èÆÀ¤¹¤ë
+        * @access public
+        * @return string ¥Ú¡¼¥¸Ì¾
+        */
+       public function getPageName()
+       {
+               $pageName = $this->pageName;
+               $this->pageName += 1;
+
+               return $pageName;
+       }
+
+       /**
+        * ¥Ú¡¼¥¸ID¤ò¼èÆÀ¤¹¤ë
+        * @access public
+        * @param string $pageName ¥Ú¡¼¥¸Ì¾
+        * @return int ¥Ú¡¼¥¸ID
+        */
+       public function getPageID($pageName)
+       {
+               return $this->request->getParameter($pageName, 1);
+       }
+}
+?>