Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. App::uses('AuthComponent', 'Controller/Component');
  2.  
  3. class Task extends AppModel {
  4.  
  5. public $belongsTo = 'User';
  6.  
  7. public $validate = array(
  8. 'task_name' => array(
  9. 'custom' => array(
  10. 'rule' => array('custom', '/^[a-z0-9 ]*$/i'),
  11. 'required' => true,
  12. 'message' => 'This field accepts letters and numbers only.'
  13. ),
  14. 'maxLength' => array(
  15. 'rule' => array('maxLength', 50),
  16. 'message' => 'Task name cannot exceed 50 characters'
  17. )
  18. ),
  19. 'frequency' => array(
  20. 'alphaNumeric' => array(
  21. 'rule' => 'alphaNumeric',
  22. 'allowEmpty' => true
  23. )
  24. ),
  25. 'day' => array(
  26. 'alphaNumeric' => array(
  27. 'rule' => 'alphaNumeric',
  28. 'allowEmpty' => true
  29. )
  30. ),
  31. 'user_id' => array(
  32. 'numeric' => array(
  33. 'rule' => 'numeric'
  34. )
  35. ),
  36. 'month_type' => array(
  37. 'alphaNumeric' => array(
  38. 'rule' => 'alphaNumeric',
  39. 'required' => false
  40. )
  41. ),
  42. 'month_number' => array(
  43. 'alphaNumeric' => array(
  44. 'rule' => 'alphaNumeric',
  45. 'required' => false
  46. )
  47. ),
  48. 'month_day' => array(
  49. 'alphaNumeric' => array(
  50. 'rule' => 'alphaNumeric',
  51. 'allowEmpty' => true
  52. )
  53. ),
  54. 'day_number' => array(
  55. 'alphaNumeric' => array(
  56. 'rule' => 'alphaNumeric',
  57. 'required' => false
  58. )
  59. )
  60. );
  61. }
  62.  
  63. public function add() {
  64. if ($this->request->is('post')) {
  65. $this->Task->create();
  66. if ($this->Task->save($this->request->data)) {
  67. $this->Session->setFlash(__('Task saved!'));
  68. $this->redirect(array('action' => 'index'));
  69. }
  70. else {
  71. $this->Session->setFlash(__('The task could not be saved'));
  72. }
  73. }
  74. }
  75.  
  76. <?php
  77. echo $this->Form->create('Task',array('class' => 'taskForm'));
  78. $userId = $this->Session->read('Auth.User.id');?>
  79.  
  80. <fieldset>
  81. <legend class="welcomeText"><?php echo __('Add a Task'); ?></legend>
  82. <?php
  83.  
  84. echo $this->Form->hidden('user_id', array('value' => $userId));
  85.  
  86. echo $this->Form->input('task_name', array('label' => 'Task Name', 'maxLength' => 50));
  87.  
  88. //set frequency
  89. echo "<p>How often should this task be done?</p>";
  90. $options = array('unset' => 'Decide Later','daily' => 'Daily','weekly' => 'Weekly','monthly' => 'Monthly');
  91. $attributes = array('value' => 'unset','separator' => '<br/>','class' => 'frequencyRadio','legend' => false);
  92. echo $this->Form->radio('frequency', $options, $attributes);
  93.  
  94. //optional answers
  95.  
  96. //if "weekly" is selected
  97. echo "<div id="weeklyRadio" >";
  98. echo "<p>Set a day of the week for this task?</p>";
  99. $options = array('unset' => 'Decide later','monday' => 'Monday','tuesday' => 'Tuesday','wednesday' => 'Wednesday',
  100. 'thursday' => 'Thursday','friday' => 'Friday','saturday' => 'Saturday','sunday' => 'Sunday');
  101. $attributes = array('value' => 'unset','separator' => '<br/>','class' => 'weeklyRadio','legend' => false);
  102. echo $this->Form->radio('day',$options,$attributes);
  103. echo "</div>";
  104.  
  105. //if "monthly" is selected
  106. ?>
  107. <div id="monthlyRadio">
  108. <p>Schedule this task?</p>
  109. <input type="radio" name="data[Task][month_type]" id="TaskMonthTypeUnset"
  110. value="unset" class="monthlyRadio" required="required" checked="checked" />
  111. <label for="TaskMonthTypeUnset">Decide later</label><br/>
  112. <input type="radio" name="data[Task][month_type]" id="TaskMonthTypeNumber"
  113. value="number" class="monthlyRadio" required="required" />
  114. <label for="TaskMonthTypeNumber">
  115. <?php
  116.  
  117. echo "On the ";
  118. $options = array(1 => '1st',2 => '2nd',3 => '3rd',4 => '4th',5 => '5th',6 => '6th',7 => '7th',8 => '8th',9 => '9th',
  119. 10 => '10th',11 => '11th',12 => '12th',13 => '13th',14 => '14th',15 => '15th', 16 => '16th',
  120. 17 => '17th',18 => '18th',19 => '19th',20 => '20th',21 => '21st',22 => '22nd',23 => '23rd',
  121. 24 => '24th',25 => '25th',26 => '26th',27 => '27th',28 => '28th',29 => '29th',30 => '30th',31 => '31st');
  122. echo $this->Form->select('month_number',$options,array('value' => null));
  123. echo " of the month";
  124. ?>
  125. </label><br/>
  126. <input type="radio" name="data[Task][month_type]" id="TaskMonthTypeDay" value="day" class="monthlyRadio" required="required" />
  127. <label for="TaskMonthTypeDay">
  128. <?php
  129.  
  130. echo "On the ";
  131. $options = array(1 => '1st',2 => '2nd',3 => '3rd',4 => '4th',5 => '5th',6 => 'last');
  132. echo $this->Form->select('day_number',$options,array('value' => null));
  133. echo "&nbsp";
  134. $options = array('monday' => 'Monday','tuesday' => 'Tuesday','wednesday' => 'Wednesday',
  135. 'thursday' => 'Thursday','friday' => 'Friday','saturday' => 'Saturday','sunday' => 'Sunday');
  136. echo $this->Form->select('month_day',$options,array('value' => null));
  137. echo " of the month";
  138. ?>
  139. </label>
  140. </div>
  141.  
  142.  
  143.  
  144.  
  145. <?php
  146. echo $this->Form->submit('Add Task', array('class' => 'formSubmit', 'title' => 'Create Task') );
  147. ?>
  148. </fieldset>
  149. <?php echo $this->Form->end(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement