Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function dateAchievedNewprogress() {
- /* sw_task dateAchievedNewprogress
- {
- "summary":"Description photo",
- "responses":"dateAchieved_response",
- "parameters":[{"schema":"param_dateAchieved","description":"Parament for photos"}]
- } */
- /* sw_model param_dateAchieved
- {
- "properties":{
- "chid":{
- "type":"integer",
- "example" : 2,
- "description":"child id"
- },
- "type":{
- "type":"string",
- "example" :"cl",
- "description":"data"
- },
- "tab":{
- "note":"string",
- "example" : "tab1",
- "description":"id item for delete"
- },
- "itemid":{
- "note":"string",
- "example" : "CLT97",
- "description":"id item for delete"
- },
- "date":{
- "note":"string",
- "example" : "09.08.2015",
- "description":"id item for delete"
- },
- "action":{
- "note":"string",
- "example" : "1",
- "description":"id item for delete"
- }
- }
- } */
- /* sw_model dateAchieved_response
- {
- "properties":{
- "result":"Object",
- "schema":"dateAchieved_response_result",
- "description":"result info",
- }
- }
- } */
- /* sw_model dateAchieved_response_result
- {
- "properties":{
- "msg":{
- "type":"string",
- "description":""
- },
- "complete":{
- "type":"boolean",
- "description":""
- }
- }
- } */
- $this->requireAccess();
- $init_vars =
- [
- 'action',
- 'record_id',
- 'chid',
- 'tab',
- 'type',
- //'aid',
- ];
- $required =
- [
- 'date',
- ];
- $vars = $this->importVariables($init_vars, $required);
- if (empty($date)) {
- $result['msg'] = 'Error: date empty';
- $result['complete'] = FALSE;
- $this->jsonize(array(
- 'result' => $result
- ));
- }
- //$aid = JRequest::getVar('aid', '', '', '');
- $aid_name = $this->getAdminName(JFactory::getUser()->get('id'));
- /* FIX OF EMPTY TYPE */
- $vars->type = preg_replace("/[0-9]/", '', $vars->record_id);
- $vars->type = strtolower(str_replace("T", '', $vars->type));
- $letters = [
- 'l' => 'lt',
- 'm' => 'mt',
- 'uw' => 'utw',
- 'a' => 'at',
- ];
- foreach($letters as $key => $value)
- {
- if ($vars->type == $key)
- {
- $vars->type = $value;
- break;
- }
- }
- $db = JFactory::getDBO();
- $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');
- $db->setQuery('SELECT * FROM #__sted_newprogress_achieved WHERE child_id =' . $vars->chid . ' AND `type`="' . $vars->type . '" AND `key` = "'.$vars->record_id.'" AND years2=0');
- $this->send_to_log($db->loadAssoc());
- $somevar[$vars->tab] = unserialize($progress_optimized[$vars->tab]);
- $textMsg = '';
- $a =& $somevar[$vars->tab][$vars->record_id];
- $this->send_to_log($vars->action);
- if ($vars->action == 1)
- {
- $textMsg = empty($a['date']) ? 'add' : 'edit';
- $a['date'] = $vars->date;
- $a['aid'] = $vars->aid;
- $a['aid_name'] = $aid_name;
- } else if ($vars->action == 2)
- {
- $textMsg = 'delete';
- $a['date'] = '';
- $a['aid'] = '';
- $a['aid_name'] = '';
- }
- /* PART 3 */
- $completed = 0;
- $areas = count($somevar[$vars->tab]);
- // for($i=$data[$tab]['start'], $completed=0; $i<=$data[$tab]['end'];$i++){
- // if($somevar[$tab][$name_type.$i]['date']!=''){$completed++;}
- // }
- /* PART 3 */
- /* PART 4 */
- $s_data = serialize($somevar[$vars->tab]);
- // 08.01.13 FIX FOR single quote
- if(empty($progress_optimized))
- {
- list($day, $month, $year) = explode(".", $vars->date);
- $toSave = [
- $vars->chid,
- $db->quote($vars->type),
- $db->quote($vars->record_id),
- preg_replace("/[^0-9]/", '', $vars->record_id),
- $db->quote($vars->tab),
- $db->quote($year."-".$month."-". $day),
- $aid,
- $db->quote($aid_name),
- 0,
- ];
- $insert = $db->getQuery(true);
- $insert->insert($db->quoteName("#__sted_newprogress_achieved"))
- ->columns($db->quoteName(array("child_id", "type", "key", "progress_item", "tab", "date", "aid", "aid_name", "years2")))
- ->values(implode(",", $toSave));
- $this->send_to_log($insert->__toString());
- $db->setQuery($insert);
- $db->query();
- }
- // $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";
- // $db->setQuery($query);
- // $db->query();
- if ($vars->action == 1) {
- $push_model = $this->getModelFromSted('push');
- $push_model->add_date_progress($vars->record_id, $vars->tab, $vars->chid);
- }
- $result['msg'] = 'date achieved ' . $textMsg . ' complete.';
- $result['complete'] = true;
- // JSONize
- $this->jsonize(array(
- 'result' => $result
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement