centralM
[ class tree: centralM ] [ index: centralM ] [ all elements ]

Source for file actions.class.php

Documentation is available at actions.class.php

  1. <?php
  2.  
  3. /**
  4.  * mac actions.
  5.  *
  6.  * @package    centralM
  7.  * @subpackage mac
  8.  * @author     Your name here
  9.  * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
  10.  */
  11. class macActions extends sfActions
  12. {
  13.   public function executeIndex(sfWebRequest $request)
  14.   {
  15.     $this->etva_mac_list EtvaMacPeer::doSelect(new Criteria());
  16.   }
  17.  
  18.   public function executeCreatewin(sfWebRequest $request)
  19.   {
  20.       
  21.   }
  22.  
  23. //  public function executeJsonUpdate(sfWebRequest $request){
  24. //
  25. //    $mac = $request->getParameter('mac');
  26. //    $query = ($this->getRequestParameter('query'))? json_decode($this->getRequestParameter('query'),true) : array();
  27. //
  28. //
  29. //    $criteria = new Criteria();
  30. //    $criteria->add(EtvaMacPeer::MAC, $mac);
  31. //
  32. //    $etva_mac = EtvaMacPeer::doSelectOne($criteria);
  33. //
  34. //    foreach($query as $key=>$val){
  35. //        $column = EtvaMacPeer::translateFieldName(sfInflector::camelize($key), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
  36. //        $etva_mac->setByName($column, $val);
  37. //        $etva_mac->save();
  38. //
  39. //    }
  40. //
  41. //    $result = array('success'=>true);
  42. //    $result = json_encode($result);
  43. //
  44. //    $this->getContext()->getResponse()->setHttpHeader("X-JSON", '()'); // set a header, (although it is empty, it is nicer than without a correct header. Filling the header with the result will not be parsed by extjs as far as I have seen).
  45. //
  46. //    return $this->renderText($result);
  47. //
  48. //
  49. //  }
  50.  
  51.   public function executeJsonGetUnused(sfWebRequest $request)
  52.   {
  53.     $isAjax $request->isXmlHttpRequest();
  54.  
  55.    // if(!$isAjax) return $this->redirect('@homepage');
  56. // $this->getUser()->getAttributeHolder()->remove('macs_in_wizard');
  57.     $criteria new Criteria();
  58.     
  59.     $session_macs $this->getUser()->getAttribute('macs_in_wizard'array());
  60.     //if($session_macs){ print_r($session_macs);
  61.     //    die();
  62.    // }
  63.     $macs_in_use array();
  64.     foreach($session_macs as $index=>$item){
  65.         //$value = $item->getMac();
  66.         $macs_in_use[$item['Id'];
  67.         
  68.     }
  69.  
  70.     $criteria->add(EtvaMacPeer::ID$macs_in_useCriteria::NOT_IN);
  71.     $criteria->add(EtvaMacPeer::IN_USE0);
  72.     
  73.     $etva_mac EtvaMacPeer::doSelectOne($criteria);
  74.  
  75.     if(!$etva_mac){
  76.         $info array('success'=>false,'errors'=>'No macs available in pool');
  77.         $error $this->setJsonError($info);
  78.         return $this->renderText($error);
  79.     }
  80.  
  81.     $mac $etva_mac->toArray();
  82.  
  83.     // fetch jobs already stored in the job history
  84.     // $session_macs = $this->getUser()->getAttribute('macs_in_wizard', array());
  85.  
  86.     // add the current job at the beginning of the array
  87.     array_unshift($session_macs$mac);
  88.  
  89.     // store the new job history back into the session
  90.     $this->getUser()->setAttribute('macs_in_wizard'$session_macs);
  91.  
  92.    
  93.  
  94.  
  95.     // Store data in the user session
  96.     // $this->getUser()->setAttribute('macs_in_wizard', array$mac);
  97.  
  98.     // mark has taken
  99.    // $etva_mac->setInUse(1);
  100.    // $etva_mac->save();
  101.  
  102.     
  103.     $result json_encode($mac);
  104.  
  105.     $this->getResponse()->setHttpHeader("X-JSON"'()')// set a header, (although it is empty, it is nicer than without a correct header. Filling the header with the result will not be parsed by extjs as far as I have seen).
  106.     return $this->renderText($result);
  107.  
  108.  
  109.   }
  110.  
  111.   public function executeJsonGeneratePool(sfWebRequest $request)
  112.   {
  113.   
  114.  
  115.     $isAjax $request->isXmlHttpRequest();
  116.  
  117.     if(!$isAjaxreturn $this->redirect('@homepage');
  118.  
  119.     $macs $this->generateMacPool($request->getParameter('size'));
  120.  
  121.     foreach($macs as $mac){
  122.             $etva_mac new EtvaMac();
  123.             $etva_mac->setMac($mac);
  124.             $etva_mac->save();
  125.  
  126.     }
  127.     $result array('success'=>true);
  128.     $result json_encode($result);
  129.  
  130.     $this->getContext()->getResponse()->setHttpHeader("X-JSON"'()')// set a header, (although it is empty, it is nicer than without a correct header. Filling the header with the result will not be parsed by extjs as far as I have seen).
  131.  
  132.     return $this->renderText($result);
  133.  
  134.   }
  135.  
  136.   protected function generateMacPool($pool_size)
  137.   {
  138.  
  139.      $macs array();
  140.  
  141.      for($i=0;$i<$pool_size;$i++){
  142.      $rmac join(":",array(
  143.                             sprintf('%02x',0x00),
  144.                              sprintf('%02x',0x16),
  145.                              sprintf('%02x',0x3e),
  146.                              sprintf('%02x',mt_rand(1,127)),
  147.                              sprintf('%02x',mt_rand(1,255)),
  148.                              sprintf('%02x',mt_rand(1,255))
  149.                          ));
  150.                     $macs[$rmac;
  151.      }
  152.  
  153.  
  154.  
  155.      return $macs;
  156.  
  157.   }
  158.  
  159.  
  160.   public function executeJsonGridAll(sfWebRequest $request)
  161.   {
  162.  
  163.     $isAjax $request->isXmlHttpRequest();
  164.  
  165.     if(!$isAjaxreturn $this->redirect('@homepage');
  166.     $macs array();  
  167.  
  168.     $query ($this->getRequestParameter('query'))json_decode($this->getRequestParameter('query'),truearray();
  169.   
  170.  
  171.     $criteria new Criteria();    
  172.  
  173.     foreach($query as $key=>$val){
  174.         
  175.         $column EtvaMacPeer::translateFieldName(sfInflector::camelize($key)BasePeer::TYPE_PHPNAMEBasePeer::TYPE_COLNAME);       
  176.         $criteria->add($column$val);
  177.     }
  178.     
  179.  
  180.     $this->etva_mac_list EtvaMacPeer::doSelect($criteria);
  181.  
  182.     foreach ($this->etva_mac_list as $etva_mac)
  183.     {
  184.             $macs[$etva_mac->toArray();
  185.     }
  186.  
  187.  
  188.     $final array(
  189.       'total' =>   count($macs),
  190.       'data'  => $macs
  191.     );
  192.  
  193.     $result json_encode($final);
  194.  
  195.     $this->getResponse()->setHttpHeader("X-JSON"'()')// set a header, (although it is empty, it is nicer than without a correct header. Filling the header with the result will not be parsed by extjs as far as I have seen).
  196.     return $this->renderText($result);
  197.     
  198.   }
  199.  
  200.   public function executeJsonTree(sfWebRequest $request)
  201.   {
  202.     $etva_mac_list EtvaMacPeer::doSelect(new Criteria());
  203.  
  204.     $tree array();
  205.     foreach($etva_mac_list as $mac)
  206.                 $tree[array('id'=>$mac->getId(),'uiProvider'=>'col','iconCls'=>'devices-folder','text'=> $mac->getMac(),'in_use'=>$mac->getInUse(),'singleClickExpand'=>true,'leaf'=>true);
  207.  
  208.  
  209.  
  210.     $result json_encode($tree);
  211.  
  212.     $this->getResponse()->setHttpHeader("X-JSON"'()');
  213.     return $this->renderText($result);
  214.   }
  215.  
  216.   public function executeNew(sfWebRequest $request)
  217.   {
  218.     $this->form new EtvaMacForm();
  219.   }
  220.  
  221.   public function executeCreate(sfWebRequest $request)
  222.   {
  223.     $this->forward404Unless($request->isMethod('post'));
  224.  
  225.     $this->form new EtvaMacForm();
  226.  
  227.     $this->processForm($request$this->form);
  228.  
  229.     $this->setTemplate('new');
  230.   }
  231.  
  232.   public function executeEdit(sfWebRequest $request)
  233.   {
  234.     $this->forward404Unless($etva_mac EtvaMacPeer::retrieveByPk($request->getParameter('id'))sprintf('Object etva_mac does not exist (%s).'$request->getParameter('id')));
  235.     $this->form new EtvaMacForm($etva_mac);
  236.   }
  237.  
  238.   public function executeUpdate(sfWebRequest $request)
  239.   {
  240.     $this->forward404Unless($request->isMethod('post'|| $request->isMethod('put'));
  241.     $this->forward404Unless($etva_mac EtvaMacPeer::retrieveByPk($request->getParameter('id'))sprintf('Object etva_mac does not exist (%s).'$request->getParameter('id')));
  242.     $this->form new EtvaMacForm($etva_mac);
  243.  
  244.     $this->processForm($request$this->form);
  245.  
  246.     $this->setTemplate('edit');
  247.   }
  248.  
  249.   public function executeDelete(sfWebRequest $request)
  250.   {
  251.     $request->checkCSRFProtection();
  252.  
  253.     $this->forward404Unless($etva_mac EtvaMacPeer::retrieveByPk($request->getParameter('id'))sprintf('Object etva_mac does not exist (%s).'$request->getParameter('id')));
  254.     $etva_mac->delete();
  255.  
  256.     $this->redirect('mac/index');
  257.   }
  258.  
  259.   protected function processForm(sfWebRequest $requestsfForm $form)
  260.   {
  261.     $form->bind($request->getParameter($form->getName())$request->getFiles($form->getName()));
  262.     if ($form->isValid())
  263.     {
  264.       $etva_mac $form->save();
  265.  
  266.       $this->redirect('mac/edit?id='.$etva_mac->getId());
  267.     }
  268.   }
  269.  
  270.   private function setJsonError($info,$statusCode 400){
  271.  
  272.       $this->getContext()->getResponse()->setStatusCode($statusCode);
  273.       $error json_encode($info);
  274.       $this->getContext()->getResponse()->setHttpHeader("X-JSON"'()');
  275.       return $error;
  276.  
  277.   }
  278.  
  279. }

Documentation generated on Fri, 19 Jun 2009 10:46:00 +0100 by phpDocumentor 1.4.2