Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.29 KB | None | 0 0
  1. <?php
  2.  
  3. function dateAchievedNewprogress() {
  4.  
  5.     /* sw_task dateAchievedNewprogress
  6.       {
  7.       "summary":"Description photo",
  8.       "responses":"dateAchieved_response",
  9.       "parameters":[{"schema":"param_dateAchieved","description":"Parament for photos"}]
  10.  
  11.       } */
  12.  
  13.     /* sw_model param_dateAchieved
  14.       {
  15.       "properties":{
  16.       "chid":{
  17.       "type":"integer",
  18.       "example" : 2,
  19.       "description":"child id"
  20.       },
  21.       "type":{
  22.       "type":"string",
  23.       "example" :"cl",
  24.       "description":"data"
  25.       },
  26.       "tab":{
  27.       "note":"string",
  28.       "example" : "tab1",
  29.       "description":"id item for delete"
  30.       },
  31.       "itemid":{
  32.       "note":"string",
  33.       "example" : "CLT97",
  34.       "description":"id item for delete"
  35.       },
  36.       "date":{
  37.       "note":"string",
  38.       "example" : "09.08.2015",
  39.       "description":"id item for delete"
  40.       },
  41.       "action":{
  42.       "note":"string",
  43.       "example" : "1",
  44.       "description":"id item for delete"
  45.       }
  46.       }
  47.       } */
  48.  
  49.     /* sw_model dateAchieved_response
  50.       {
  51.       "properties":{
  52.       "result":"Object",
  53.       "schema":"dateAchieved_response_result",
  54.       "description":"result info",
  55.       }
  56.       }
  57.       } */
  58.  
  59.     /* sw_model dateAchieved_response_result
  60.       {
  61.       "properties":{
  62.       "msg":{
  63.       "type":"string",
  64.       "description":""
  65.       },
  66.       "complete":{
  67.       "type":"boolean",
  68.       "description":""
  69.       }
  70.       }
  71.       } */
  72.  
  73.  
  74.     $this->requireAccess();
  75.  
  76.     $init_vars =
  77.     [
  78.       'action',
  79.       'record_id',
  80.       'chid',
  81.       'tab',
  82.       'type',
  83.       //'aid',
  84.     ];
  85.     $required =
  86.     [
  87.       'date',
  88.     ];
  89.     $vars = $this->importVariables($init_vars, $required);
  90.     if (empty($date)) {
  91.       $result['msg'] = 'Error: date empty';
  92.       $result['complete'] = FALSE;
  93.       $this->jsonize(array(
  94.           'result' => $result
  95.       ));
  96.     }
  97.  
  98.     //$aid = JRequest::getVar('aid',  '', '', '');
  99.     $aid_name = $this->getAdminName(JFactory::getUser()->get('id'));
  100.     /* FIX OF EMPTY TYPE */
  101.     $vars->type = preg_replace("/[0-9]/", '', $vars->record_id);
  102.     $vars->type = strtolower(str_replace("T", '', $vars->type));
  103.     $letters = [
  104.       'l' => 'lt',
  105.       'm' => 'mt',
  106.       'uw' => 'utw',
  107.       'a' => 'at',
  108.     ];
  109.     foreach($letters as $key => $value)
  110.     {
  111.       if ($vars->type == $key)
  112.       {
  113.         $vars->type = $value;
  114.         break;
  115.       }
  116.     }
  117.  
  118.     $db = JFactory::getDBO();
  119.     $this->send_to_log('SELECT * FROM #__sted_newprogress_achieved WHERE child_id =' . $vars->chid . ' AND `type`="' . $vars->type . '" AND `key` = "'.$vars->record_id.'" AND years2=0');
  120.     $db->setQuery('SELECT * FROM #__sted_newprogress_achieved WHERE child_id =' . $vars->chid . ' AND `type`="' . $vars->type . '" AND `key` = "'.$vars->record_id.'" AND years2=0');
  121.     $this->send_to_log($db->loadAssoc());
  122.     $somevar[$vars->tab] = unserialize($progress_optimized[$vars->tab]);
  123.     $textMsg = '';
  124.     $a =& $somevar[$vars->tab][$vars->record_id];
  125.     $this->send_to_log($vars->action);
  126.     if ($vars->action == 1)
  127.     {
  128.       $textMsg = empty($a['date']) ? 'add' : 'edit';
  129.       $a['date'] = $vars->date;
  130.       $a['aid'] = $vars->aid;
  131.       $a['aid_name'] = $aid_name;
  132.     } else if ($vars->action == 2)
  133.     {
  134.       $textMsg = 'delete';
  135.       $a['date'] = '';
  136.       $a['aid'] = '';
  137.       $a['aid_name'] = '';
  138.     }
  139.  
  140.     /* PART 3 */
  141.     $completed = 0;
  142.     $areas = count($somevar[$vars->tab]);
  143.     //  for($i=$data[$tab]['start'], $completed=0; $i<=$data[$tab]['end'];$i++){
  144.     //      if($somevar[$tab][$name_type.$i]['date']!=''){$completed++;}
  145.     //  }
  146.     /* PART 3 */
  147.  
  148.     /* PART 4 */
  149.     $s_data = serialize($somevar[$vars->tab]);
  150.  
  151.     // 08.01.13 FIX FOR single quote
  152.     if(empty($progress_optimized))
  153.     {
  154.         list($day, $month, $year) = explode(".", $vars->date);
  155.        
  156.         $toSave = [
  157.           $vars->chid,
  158.           $db->quote($vars->type),
  159.           $db->quote($vars->record_id),
  160.           preg_replace("/[^0-9]/", '', $vars->record_id),
  161.           $db->quote($vars->tab),
  162.           $db->quote($year."-".$month."-". $day),
  163.           $aid,
  164.           $db->quote($aid_name),
  165.           0,
  166.         ];
  167.  
  168.         $insert = $db->getQuery(true);
  169.         $insert->insert($db->quoteName("#__sted_newprogress_achieved"))
  170.             ->columns($db->quoteName(array("child_id", "type", "key", "progress_item", "tab", "date", "aid", "aid_name", "years2")))
  171.             ->values(implode(",", $toSave));
  172.         $this->send_to_log($insert->__toString());
  173.         $db->setQuery($insert);
  174.         $db->query();
  175.     }
  176.  
  177. //      $query = "UPDATE #__sted_newprogress SET " . $tab . "='" . $db->escape($s_data) . "', " . $tab . "_areas='" . $areas . "', " . $tab . "_completed='" . $completed . "' WHERE chid =" . $chid . " AND type=\"" . $type . "\" AND years2=0";
  178.  
  179. //     $db->setQuery($query);
  180. //      $db->query();
  181.  
  182.     if ($vars->action == 1) {
  183.       $push_model = $this->getModelFromSted('push');
  184.       $push_model->add_date_progress($vars->record_id, $vars->tab, $vars->chid);
  185.     }
  186.     $result['msg'] = 'date achieved ' . $textMsg . ' complete.';
  187.     $result['complete'] = true;
  188.  
  189.     // JSONize
  190.     $this->jsonize(array(
  191.         'result' => $result
  192.     ));
  193.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement