abstractController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\process;
  3. use MGModule\DNSManager2 as main;
  4. /**
  5. * Description of abstractController
  6. *
  7. * @author Michal Czech <michael@modulesgarden.com>
  8. */
  9. abstract class abstractController {
  10. public $mgToken = null;
  11. private $registredValidationErros = array();
  12. function __construct($input) {
  13. if(isset($input['mg-token']))
  14. {
  15. $this->mgToken = $input['mg-token'];
  16. }
  17. }
  18. /**
  19. * Generate Token For Form
  20. *
  21. * @author Michal Czech <michael@modulesgarden.com>
  22. * @return string
  23. */
  24. function genToken(){
  25. return md5(time());
  26. }
  27. /**
  28. * Validate Token With previous checked
  29. *
  30. * @author Michal Czech <michael@modulesgarden.com>
  31. * @param string $token
  32. * @return boolean
  33. */
  34. function checkToken($token = null){
  35. if($token === null)
  36. {
  37. $token = $this->mgToken;
  38. }
  39. if($_SESSION['mg-token'] === $token)
  40. {
  41. return false;
  42. }
  43. $_SESSION['mg-token'] = $token;
  44. return true;
  45. }
  46. function dataTablesParseRow($template,$data){
  47. $row = main\mgLibs\smarty::I()->view($template,$data);
  48. $output = array();
  49. if(preg_match_all('/\<td\>(?P<col>.*?)\<\/td\>/s', $row, $result))
  50. {
  51. foreach($result['col'] as $col)
  52. {
  53. $output[] = $col;
  54. }
  55. }
  56. return $output;
  57. }
  58. function registerErrors($errors){
  59. $this->registredValidationErros = $errors;
  60. }
  61. function getFieldError($field,$langspace='validationErrors'){
  62. if(!isset($this->registredValidationErros[$field]))
  63. {
  64. return false;
  65. }
  66. $message = array();
  67. foreach($this->registredValidationErros[$field] as $type)
  68. {
  69. $message[] = main\mgLibs\lang::absoluteT($langspace,$type);
  70. }
  71. return implode(',',$message);
  72. }
  73. }