コード例 #1
0
 function edit($id)
 {
     $this->Party->id = $id;
     $party = $this->Party->read();
     $this->set('party', $party);
     $this->pageTitle = 'Edit Party';
     $this->set('current', 'create');
     if (empty($_SESSION['User']['id'])) {
         $this->redirect('/users/login/');
     }
     if ($party['Party']['owner'] != $_SESSION['User']['id']) {
         $this->redirect('/parties/view/' . $id);
     } else {
         if (empty($this->data)) {
             $this->data = $party;
             $date = array('hour' => intval(date('h', $party['Party']['date'])), 'min' => intval(date('i', $party['Party']['date'])), 'mon' => intval(date('m', $party['Party']['date'])), 'day' => intval(date('d', $party['Party']['date'])), 'year' => intval(date('Y', $party['Party']['date'])), 'tz' => $party['Party']['tz']);
             $this->set('date', $date);
             $this->data['Party']['name'] = preg_replace("/&#(\\d{2,5});/e", '$this->Unicode->unicode2utf(${1})', html_entity_decode($this->data['Party']['name']));
             $this->data['Party']['vname'] = preg_replace("/&#(\\d{2,5});/e", '$this->Unicode->unicode2utf(${1})', html_entity_decode($this->data['Party']['vname']));
             $this->data['Party']['website'] = preg_replace("/&#(\\d{2,5});/e", '$this->Unicode->unicode2utf(${1})', html_entity_decode($this->data['Party']['website']));
             $this->data['Party']['address'] = preg_replace("/&#(\\d{2,5});/e", '$this->Unicode->unicode2utf(${1})', html_entity_decode($this->data['Party']['address']));
             $this->data['Party']['notes'] = preg_replace("/&#(\\d{2,5});/e", '$this->Unicode->unicode2utf(${1})', html_entity_decode($this->data['Party']['notes']));
             $this->data['Party']['flickrusr'] = preg_replace("/&#(\\d{2,5});/e", '$this->Unicode->unicode2utf(${1})', html_entity_decode($this->data['Party']['flickrusr']));
             if (GMAP_API_KEY != null) {
                 if ($this->data['Party']['lat']) {
                     $this->set('map', 'mapInit(' . $this->data['Party']['lat'] . ',' . $this->data['Party']['long'] . ',' . $this->data['Party']['zoom'] . ')');
                 } else {
                     $this->set('map', 'mapInit()');
                 }
             }
         } else {
             $clean = new Sanitize();
             $temp = array('lat' => $clean->sql($this->data['Party']['lat']), 'long' => $clean->sql($this->data['Party']['long']), 'tz' => $clean->sql($this->data['Party']['tz']));
             $clean->cleanArray($this->data);
             $this->data['Party']['lat'] = floatval($temp['lat']);
             $this->data['Party']['long'] = floatval($temp['long']);
             $this->data['Party']['tz'] = intval($temp['tz']);
             $secoffset = $this->data['Party']['tz'] * 60 * 60;
             $offsetdate = gmmktime($this->data['Party']['hour_hour'], $this->data['Party']['minute_min'], 0, $this->data['Party']['month_hour'], $this->data['Party']['day_day'], $this->data['Party']['year_year']);
             $this->data['Party']['date'] = $offsetdate - $secoffset;
             $this->data['Party']['owner'] = $party['Party']['owner'];
             $this->data['Party']['duration'] = intval($this->data['Party']['duration']);
             $date = array('hour' => intval(date('h', $party['Party']['date'])), 'min' => intval(date('i', $party['Party']['date'])), 'mon' => intval(date('m', $party['Party']['date'])), 'day' => intval(date('d', $party['Party']['date'])), 'year' => intval(date('Y', $party['Party']['date'])), 'tz' => $party['Party']['tz']);
             $this->set('date', $date);
             if (!preg_match("/^(http|https)\\:\\/\\//i", $this->data['Party']['website']) && !empty($this->data['Party']['website'])) {
                 $this->Party->invalidate('website');
             }
             if ($this->data['Party']['flickrusr'] != $party['Party']['flickrusr']) {
                 $params = array('type' => 'flickr', 'username' => $this->data['Party']['flickrusr']);
                 $flick = new webServices($params);
                 $this->data['Party']['flickrid'] = $flick->getFlickrId();
             }
             if ($this->Party->validates($this->data)) {
                 if ($this->Party->save($this->data)) {
                     $this->Session->setFlash('Party edited successfully.', 'infoFlash');
                     $this->redirect('parties/view/' . $id);
                 }
             }
         }
     }
 }