function update($data)
 {
     $uid = substr($data['uid'], strlen('event-'));
     $oldCalName = $data['oldCalName'];
     $calName = $data['calName'];
     $eventStart = $data['eventStart'];
     $eventEnd = $data['eventEnd'];
     $eventText = $data['eventText'];
     if ($calName == null) {
         throw new Exception("no calendar name");
     }
     if ($uid == '' && ($eventStart == null || $eventEnd == null)) {
         throw new Exception("no start/end date");
     }
     if ($uid == '' && $eventText == '') {
         throw new Exception("haven't created event because text is empty");
     }
     if ($oldCalName != null) {
         // we have an old calendar, so move event from that cal to $calName
         // possibly updating event summary as well
         $this->moveEvent($uid, $eventText, $oldCalName, $calName);
     } else {
         if ($uid == '') {
             // No UID so create a new event
             $event = new vevent();
             $event->setProperty('summary', $eventText);
             $event->setProperty('dtstart', $eventStart, array('VALUE' => 'DATE'));
             $event->setProperty('dtend', $eventEnd, array('VALUE' => 'DATE'));
             $uid = $event->getProperty('uid');
             $cal = new Calendar($calName);
             $cal->setComponent($event);
             $cal->save();
             return $uid;
         } else {
             if ($eventText === '') {
                 // Event text is now empty, so delete event
                 $cal = new Calendar($calName);
                 $cal->deleteComponent($uid);
                 $cal->save();
             } else {
                 // Update the event
                 $cal = new Calendar($calName);
                 $event = $cal->getComponent($uid);
                 if ($eventText != null) {
                     $event->setProperty('summary', $eventText);
                 }
                 if ($eventStart != null) {
                     $event->setProperty('dtstart', $eventStart, array('VALUE' => 'DATE'));
                 }
                 if ($eventEnd != null) {
                     $event->setProperty('dtend', $eventEnd, array('VALUE' => 'DATE'));
                 }
                 $cal->setComponent($event, $uid);
                 $cal->save();
             }
         }
     }
 }
 public function actionAdd()
 {
     if (isset($_POST['date'])) {
         $day = explode('__', $_POST['date']);
         $model = new Calendar();
         $model->uid = Yii::app()->user->id;
         $model->day = $day[2] . "-" . $day[1] . "-" . $day[0];
         $model->save();
     }
 }
Beispiel #3
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $calendar = new Calendar($id);
         $_POST['user_id'] = $this->session->userdata('id');
         $_POST['start'] = Date2DB($_POST['start']);
         $_POST['end'] = $_POST['end'] ? Date2DB($_POST['end']) : $_POST['start'];
         $calendar->from_array($_POST);
         $calendar->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('calendars/admin/calendars');
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Calendar();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Calendar'])) {
         $model->attributes = $_POST['Calendar'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id_calendar));
         }
     }
     $this->render('create', array('model' => $model));
 }
Beispiel #5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Calendar'])) {
         $pn = Project::model()->findByPk($_POST['Calendar']['project_id'])->project_name;
         $model = new Calendar();
         $model->attributes = $_POST['Calendar'];
         $model->description = $_POST['Calendar']['description'] . " of";
         if ($model->save()) {
             echo "sukses";
         } else {
             print_r($model->getErrors());
         }
         // $this->redirect(array('view','id'=>$model->id));
     }
     // $this->render('create',array(
     // 'model'=>$model,
     // ));
 }
Beispiel #6
0
 public function actionNew()
 {
     //cek eror tidaknya
     // foreach  ($_FILES['fileupload']['error'] as $error ){
     // 	// if ($error
     // 	if  ($error==0)
     // 		$no_error = true;
     // 	else
     // 		$no_error = false;
     // }
     // print_r($_FILES['fileupload']);
     // exit;
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $model = new Project();
         $model->id_member = $_REQUEST['member'];
         $model->project_name = $_REQUEST['name'];
         $model->start_date = $_REQUEST['start'];
         $model->due_date = $_REQUEST['due'];
         $model->username = 1;
         $model->task = 1;
         $model->progres = 0;
         $model->priority = 1;
         $model->worker = 0;
         $model->status = 1;
         if ($model->save()) {
             $calendar = new Calendar();
             $calendar->project_id = $model->id;
             $calendar->start_date = $_REQUEST['start'];
             $calendar->due_date = $_REQUEST['due'];
             $calendar->description = $_REQUEST['descriptionca'] . " of ";
             $calendar->type = "due";
             if ($calendar->save()) {
                 // echo "sukses";
                 if ($no_error) {
                     $time = time();
                     $hm = new ProjectCommentHead();
                     $hm->datetime = date('Y-m-d H:i:s');
                     $hm->user_id = 1;
                     $hm->project_id = $model->id;
                     $hm->type = 1;
                     if ($hm->save()) {
                         $transaction->commit();
                         // foreach($_FILES['fileupload']['tmp_name'] as $key => $tmp_name ){
                         // 	$comment = new ProjectComment;
                         // 	$file_name = $_FILES['fileupload']['name'][$key];
                         // 	$file_size =$_FILES['fileupload']['size'][$key];
                         // 	$file_tmp =$_FILES['fileupload']['tmp_name'][$key];
                         // 	$file_type=$_FILES['fileupload']['type'][$key];
                         // 	// echo Yii::app()->request->baseUrl."/img/comment/".".$file_name";
                         // 	$comment->name_file = $key.$time.$file_name;
                         // 	$comment->head_project_id = $hm->id;
                         // 	$comment->comment_id = 0;
                         // 	if  ($comment->save()){
                         // 		if (move_uploaded_file($file_tmp,Yii::app()->basePath."/../img/comment/$key$time$file_name")){
                         // 			// echo "sukses";
                         // 		}
                         // 		// else{
                         // 		// 	// echo "sukses";
                         // 		// }
                         // 	}
                         // 	// echo $file_name. " ";
                         // }
                     }
                 }
                 //kirim email start
                 Yii::import('ext.yii-mail.YiiMailMessage');
                 $message = new YiiMailMessage();
                 $message->view = "project_notif";
                 $params = array('email' => $email, 'name' => $name, 'code' => $code);
                 $message->setBody($params, 'text/html');
                 $message->subject = "New Project on vvfy";
                 $message->addTo("*****@*****.**");
                 $message->addTo("*****@*****.**");
                 $message->addTo("*****@*****.**");
                 $message->addTo("*****@*****.**");
                 $message->from = Yii::app()->params['adminEmail'];
                 //  emails to keep in cc
                 // $emails = array("*****@*****.**","*****@*****.**");
                 // // foreach($emails as $value){
                 //    $message->addCC(trim($value));
                 // }
                 // $message->from = "Support";
                 // if (Yii::app()->mail->send($message))
                 echo "sukses";
                 // else
                 // echo "gagal";
                 //kirim emai end
             }
             // echo "sukses";
         } else {
             echo json_encode($model->getErrors());
         }
     } catch (Exception $e) {
         $transaction->rollBack();
         // other actions to perform on fail (redirect, alert, etc.)
     }
 }
 /**
  * @return int
  */
 public function actionCreate()
 {
     if ($this->access > UserAccessTable::FULL_ACCESS) {
         return 0;
     }
     $inputData = $_POST;
     $inputData['propertyid'] = $this->propertyId;
     $calendarModel = new Calendar();
     $calendarModel->setAttributes($inputData);
     $result = $calendarModel->save();
     $data = $calendarModel->getAttributes();
     $data['createDate'] = date('F d, Y');
     $data['link'] = $calendarModel->link->getAttributes();
     $user = $calendarModel->link->user->getAttributes();
     $usersEmail = array();
     if ($inputData['notification'] == '1') {
         $links = $this->getPropertyMembers();
         foreach ($links as $key => $link) {
             array_push($usersEmail, $link['user']['email']);
         }
     } else {
         $usersEmail = array();
     }
     $this->layout = "emailmaster";
     $date1 = new DateTime();
     $end_date = date(strtotime($calendarModel->attributes['end_date']));
     $date1->setTimestamp($end_date);
     $real_end_date = $date1->modify('-1 day');
     $end_date1 = $real_end_date->format('F d, Y');
     $body = $this->render('../emails/emailCalendar', array('fullname' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'property' => $this->propertyName, 'start' => date('F d, Y', strtotime($calendarModel->attributes['create_date'])), 'end' => $end_date1, 'event' => $calendarModel->event, 'message' => $calendarModel->notes, 'action' => 'New'), true);
     if (!empty($usersEmail)) {
         MailHelper::send($body, "SharedKey - " . $this->propertyName . " - New  Calendar Event", $usersEmail);
     }
     echo json_encode(array('data' => $data, 'result' => $result, 'event' => $calendarModel->getAttribute('event')));
     die;
 }
Beispiel #8
0
 public function actionCalendarChange()
 {
     $action = Yii::app()->request->getParam('action', '');
     $date = Yii::app()->request->getParam('date', '');
     $m = Yii::app()->request->getParam('m', '');
     $returnArray = array();
     $status = false;
     $switch = false;
     $msg = '';
     $dateObject = DateTime::createFromFormat('Y-m-d', $date);
     if ($dateObject) {
         $modelDate = new DateTime($date);
         switch ($action) {
             case 'makeUnavailable':
                 $switch = true;
                 $modelStatus = 1;
                 $modelType = 3;
                 break;
             case 'makeAvailable':
                 $switch = true;
                 $modelStatus = 0;
                 $modelType = 3;
                 break;
             case 'removeFlag':
                 $switch = true;
                 $modelStatus = 0;
                 $modelType = 1;
                 break;
             case 'addFlag':
                 $switch = true;
                 $modelStatus = 1;
                 $modelType = 1;
                 break;
         }
         if ($switch) {
             $model = Calendar::model()->find('calendar_date = "' . $modelDate->format('Y-m-d H:i:s') . '" AND calendar_type = "' . $modelType . '" AND created_by = ' . Yii::app()->user->getInfo());
             if ($model == null) {
                 $model = new Calendar();
             }
             $model->status = $modelStatus;
             $model->message = $m;
             $model->calendar_type = $modelType;
             $model->calendar_date = $modelDate->format('Y-m-d H:i:s');
             $model->created_by = Yii::app()->user->getInfo();
             if ($model->save()) {
                 $status = true;
                 $msg = 'Success';
             } else {
                 $msg = $model->getErrors();
             }
         }
     }
     $returnArray['status'] = $status;
     $returnArray['msg'] = $msg;
     header('Content-Type: application/json');
     $return = json_encode($returnArray);
     echo $return;
     Yii::app()->end();
 }
Beispiel #9
0
$calendar = get_entity($guid);
$container_guid = get_input('container_guid');
if (!$container_guid) {
    $container_guid = $user->guid;
}
$container = get_entity($container_guid);
if (!$container || !$container->canWriteToContainer(0, 'object', Calendar::SUBTYPE)) {
    register_error(elgg_echo('events:error:container_permissions'));
    forward(REFERER);
}
$title = htmlspecialchars(get_input('title', elgg_echo('events:calendar:edit:title:placeholder')), ENT_QUOTES, 'UTF-8');
$description = get_input('description');
$tags = get_input('tags', '');
$access_id = get_input('access_id', get_default_access());
if (!$calendar) {
    $calendar = new Calendar();
    $calendar->owner_guid = $user->guid;
    $calendar->container_guid = $user->guid;
}
$calendar->title = $title;
$calendar->description = $description;
$calendar->access_id = $access_id;
$calendar->tags = string_to_tag_array($tags);
if ($calendar->save()) {
    elgg_clear_sticky_form('calendar/edit');
    system_message(elgg_echo('events:calendar:edit:success'));
    forward($calendar->getURL());
} else {
    register_error(elgg_echo('events:calendar:edit:error'));
    forward(REFERER);
}
Beispiel #10
0
 function events_move()
 {
     //$this->db->debug = TRUE;
     $calendar = new Calendar($_POST['id']);
     if ($_POST['start']) {
         list($y, $m, $d) = explode('-', $calendar->start);
         $_POST['start'] = date("Y-m-d", mktime(0, 0, 0, $m, $d + $_POST['start'], $y));
     }
     if ($_POST['end']) {
         list($y, $m, $d) = explode('-', $calendar->end);
         $_POST['end'] = date("Y-m-d", mktime(0, 0, 0, $m, $d + $_POST['end'], $y));
     }
     $calendar->from_array($_POST);
     $calendar->save();
 }
 public function actionInvite()
 {
     $newEvents = array();
     $propertyId = Yii::app()->user->getState('propertyId');
     if (isset($_POST['propId'])) {
         if (is_numeric($_POST['propId'])) {
             $propertyId = $_POST['propId'];
         }
     }
     if (!Yii::app()->request->isPostRequest) {
         echo json_encode(array('status' => 0, 'message' => 'Only Post request are allowed.'));
         die;
     }
     if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $propertyId, UserAccessTable::BASIC_ACCESS)) {
         echo json_encode(array('status' => 0, 'message' => 'You can not do this action.'));
         die;
     }
     //check login
     if (Yii::app()->user->isGuest) {
         echo json_encode(array('status' => 0, 'message' => 'Please login.'));
         die;
     }
     if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $propertyId, UserAccessTable::BASIC_ACCESS)) {
         echo json_encode(array('status' => 0, 'message' => 'You can not do this action.'));
         die;
     }
     $property = Properties::model()->findByPk($propertyId);
     $model = new InviteGuest();
     $model->setAttributes($_POST);
     //create user 2 property tables
     $u2propertyes = array();
     foreach ($model->emails as $key => $value) {
         $u2p = new User2property();
         $user = User::model()->findByAttributes(array('email' => $value));
         $newUserEmailBody = "";
         if ($user == null) {
             //need create new user
             if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
                 continue;
             }
             $user = $this->createGuestUser($value, $model->names[$key], $propertyId);
             $this->layout = "emailmaster";
             $newUserEmailBody = $this->renderPartial('../emails/emailInviteNewGuest', array('userFullName' => $user->getAttribute('firstname') . ' ' . $user->getAttribute('lastname'), 'senderFullName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'email' => $user->getAttribute('email'), 'access' => UserAccessTable::accessLevelToString(UserAccessTable::GUEST), 'password' => $user->getAttribute('password'), 'url' => basePathByHost('/')), true);
             // MailHelper::send($newUserEmailBody, "SharedKey.com - New Member Account", array($user->getAttribute('email')));
         } else {
             //we can use exist user
         }
         $checku2p = User2property::model()->findByAttributes(array('propertyId' => $propertyId, 'userId' => $user->getAttribute('id')));
         if ($checku2p != null) {
             echo json_encode(array('status' => 0, 'message' => 'User is already a member of this property.'));
             die;
         }
         $u2p->propertyId = $propertyId;
         $u2p->userId = $user->getAttribute('id');
         $u2p->access = UserAccessTable::GUEST;
         $u2p->status = UserAccessTable::STATUS_ACTIVE;
         $u2p->inviteDate = date('Y-m-d h:i:s');
         $fromDate = null;
         if (!empty($model->from)) {
             $fromDate = new DateTime($model->from);
             $u2p->fromDate = $fromDate->format('Y-m-d h:i:s');
         } else {
             $u2p->fromDate = null;
         }
         $toDate = null;
         if (!empty($model->to)) {
             $toDate = new DateTime($model->to);
             $u2p->toDate = $toDate->format('Y-m-d h:i:s');
         } else {
             $u2p->toDate = null;
         }
         $u2p->inviteUserId = Yii::app()->user->getState('id');
         $u2p->color = 'type13';
         $u2p->bookingName = $model->names[$key];
         $u2p->save();
         $this->layout = "emailmaster";
         $inviteEmail = $this->render('../emails/emailInvite', array('data' => array('fromName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'from' => isset($fromDate) ? $fromDate->format('F j, Y') : '-', 'to' => isset($toDate) ? $toDate->format('F j, Y') : '-', 'access' => UserAccessTable::accessLevelToString(UserAccessTable::GUEST), 'event' => $model->event, 'message' => nl2br($model->message), 'toUser' => $user->getAttribute('firstname') . ' ' . $user->getAttribute('lastname'), 'newUserBody' => $newUserEmailBody)), true);
         MailHelper::send($inviteEmail, "Sharedkey.com - Invitation to " . $property->getAttribute('property_name'), array($user->getAttribute('email')), "SharedKey.com", array(Yii::app()->user->getState('email')));
         $u2propertyes[$key] = $u2p;
         $username = $model->names[$key];
         $calendarEvent = new Calendar();
         $calendarEvent->create_date = $u2p->fromDate;
         $calendarEvent->end_date = $u2p->toDate;
         $calendarEvent->event = $_POST['event'];
         $calendarEvent->propertyid = $u2p->propertyId;
         $calendarEvent->notes = $model->message;
         $calendarEvent->linkid = $this->linkWithProperty->id;
         $calendarEvent->isguest = true;
         $calendarEvent->guestid = $u2p->userId;
         $calendarEvent->guestname = $model->names[$key];
         $result = $calendarEvent->save();
         $outputEvent = array("result" => true, "data" => (array) $calendarEvent->getAttributes(), "event" => $calendarEvent->event);
         $outputEvent['data']['link'] = (array) $u2p->getAttributes();
         array_push($newEvents, $outputEvent);
     }
     $users = array();
     foreach ($u2propertyes as $key => $u2p) {
         $users[$key] = $this->createViewItem($u2p);
     }
     echo json_encode(array('status' => 1, 'users' => $users, 'events' => $newEvents));
     die;
 }