/**
  * Creates a rendered Programme Crawler Field using the .ss template
  * @param type $properties an array of values to decorate the field
  * @return type a rendered template
  */
 function Field($properties = array())
 {
     $obj = $properties ? $this->customise($properties) : $this;
     $obj->Options = ArrayList::create();
     $dobj = DataObject::create();
     $dobj->MyTitle = 'No Color';
     $dobj->Value = '';
     $dobj->CSSRGB = '255 255 255';
     $dobj->CSSHex = '#ffffff';
     $dobj->CSSCMYK = '0 0 0 0';
     $obj->Options->push($dobj);
     $source = ColourSchemes::get()->sort('ID');
     if ($source) {
         foreach ($source as $value) {
             $mobj = DataObject::create();
             $mobj->MyTitle = $value->OPColor;
             $mobj->Value = $value->CSSColor;
             $mobj->CSSRGB = $value->CSSRGB;
             $mobj->CSSHex = $value->CSSHex;
             $mobj->CSSCMYK = $value->CSSCMYK;
             $obj->Options->push($mobj);
         }
     }
     // directly point to the template file
     $tmp = $obj->renderWith(BASE_PATH . '/' . OPCOLORWORKINGFOLDER . "/templates/OpColorField.ss");
     return $tmp;
 }
Example #2
0
 /**
  * Recursivity creates the SilverStripe dataobject representation of content
  * @param mixed $array
  * @return \DataObject|\DataList|null
  */
 private function parseobject($array)
 {
     if (is_object($array)) {
         if (get_class($array) == 'DataObject') {
             return $array;
         }
         $do = DataObject::create();
         foreach (get_object_vars($array) as $key => $obj) {
             if ($key == '__Type') {
                 $do->setField('Title', $obj);
             } else {
                 if (is_array($obj) || is_object($obj)) {
                     $do->setField($key, $this->parseobject($obj));
                 } else {
                     $do->setField($key, $obj);
                 }
             }
         }
         return $do;
     } else {
         if (is_array($array)) {
             $dataList = ArrayList::create();
             foreach ($array as $key => $obj) {
                 $dataList->push($this->parseobject($obj));
             }
             return $dataList;
         }
     }
     return null;
 }
Example #3
0
 /**
  * Creates a rendered Programme Crawler Field using the .ss template
  * @param type $properties an array of values to decorate the field
  * @return type a rendered template
  */
 function Field($properties = array())
 {
     $obj = $properties ? $this->customise($properties) : $this;
     $obj->Options = ArrayList::create();
     $dobj = DataObject::create(array('MyTitle' => 'No Color', 'Value' => '', 'CSSRGB' => '255 255 255', 'CSSHex' => '#ffffff', 'CSSCMYK' => '0 0 0 0'));
     $obj->Options->push($dobj);
     //go through source, if object it is a custom color, if not, get data from ColourSchemes
     foreach ($this->getSource() as $value) {
         $mobj = DataObject::create();
         if ($value instanceof Object) {
             $mobj->MyTitle = $value->OPColor;
             $mobj->Value = $value->CSSColor;
             $mobj->CSSRGB = $value->CSSRGB;
             $mobj->CSSHex = $value->CSSHex;
             $mobj->CSSCMYK = $value->CSSCMYK;
         } else {
             $cs = ColourSchemes::get()->filter('OPColor', $value)->first();
             if (!empty($cs)) {
                 $mobj->MyTitle = $cs->OPColor;
                 $mobj->Value = $cs->CSSColor;
                 $mobj->CSSRGB = $cs->CSSRGB;
                 $mobj->CSSHex = $cs->CSSHex;
                 $mobj->CSSCMYK = $cs->CSSCMYK;
             }
         }
         $obj->Options->push($mobj);
     }
     // directly point to the template file
     $tmp = $obj->renderWith(BASE_PATH . '/' . OPCOLORWORKINGFOLDER . "/templates/OpColorField.ss");
     return $tmp;
 }
Example #4
0
function notify($dao, $user_id, $notif_title, $notif_message, $link_to_content)
{
    $notification = DataObject::create($dao, "notification", array("user_id" => $user_id, "notif_title" => $notif_title, "notif_message" => $notif_message, "notif_link" => $link_to_content, "notif_departure" => date("Y-m-d H:i:s", time() + 60 * 60)));
    if ($notification) {
        return $notification->commit();
    } else {
        return false;
    }
}
 /**
  * Create log entry with initialisers and write it to the database.
  *
  * If $task or $action left out will do possibly expensive call to debug_backtrace to get calling class and function .
  *
  * SideEffects:
  *  Writes object to the database.
  *
  * @param $action - what the task action is
  * @param $task - what task is logging progress
  * @param string $message defaults to 'Started'
  * @param null $info any additional info on create
  * @return ProgressLogEntry
  */
 public static function create($task = null, $action = null, $message = ProgressLogEntry::ResultMessageStarted, $info = null)
 {
     if (is_null($task) || is_null($action)) {
         $callerInfo = self::get_caller_info();
         if (!$task) {
             $task = $callerInfo[0];
         }
         if (!$action) {
             $action = $callerInfo[1];
         }
     }
     $logEntry = parent::create(array('Task' => $task, 'Action' => $action, 'ResultMessage' => $message, 'ResultInfo' => $info));
     $logEntry->write();
     return $logEntry;
 }
 /**
  * Create a model instance and set data using config.checkfront_map paths.
  *
  * @param array $data
  * @param string $forAction
  * @param bool $updateNulls
  * @return CheckfrontModel
  */
 public static function create_from_checkfront(array $data, $forAction = self::DefaultFromAction, $updateNulls = true)
 {
     /** @var CheckfrontModel $model */
     $model = parent::create();
     return $model->fromCheckfront($data, $forAction, $updateNulls);
 }
Example #7
0
if (isset($_GET["d"]) && isset($_GET["post_id"])) {
    $direction = $_GET["d"];
    $post_id = $_GET["post_id"];
    $post_vote = DataObject::select_one($dao, "post_vote", array("vote_id"), array("user_id" => $user->user_id, "post_id" => $post_id));
    if ($post_vote) {
        echo Status::json(1, "User has already voted");
    } else {
        $post = DataObject::select_one($dao, "post", array("post_id", "post_rating_up", "post_rating_dn"), array("post_id" => $post_id));
        if ($post) {
            if ($direction == "u") {
                $post->post_rating_up++;
            } else {
                $post->post_rating_dn++;
            }
            if ($post->commit()) {
                $post_vote = DataObject::create($dao, "post_vote", array("user_id" => $user->user_id, "post_id" => $post_id));
                if ($post_vote) {
                    if ($post_vote->commit()) {
                        echo Status::json(0, "Vote added");
                    } else {
                        echo Status::json(2, "Failed to prevent future votes");
                    }
                } else {
                    echo Status::json(3, "Failed to insert post_vote");
                }
            } else {
                echo Status::json(4, "Failed to commit change post rating");
            }
        } else {
            echo Status::json(5, "Failed to select post");
        }
Example #8
0
//Add a post to a cohort/user's feed
include "../util/session.php";
include_once "../util/mysql.php";
include "../util/status.php";
include "../notification/add.php";
$group_id = -1;
//For the feed
$dao = new DAO(false);
if (isset($_POST["group_id"])) {
    //For a specific group
    $group_id = $_POST["group_id"];
}
if (isset($_POST["post_content"]) && trim($_POST["post_content"]) != "") {
    $post_content = $_POST["post_content"];
    $post_time = date("Y-m-d H:i:s", time() + 3600);
    $post = DataObject::create($dao, "post", array("user_id" => $user->user_id, "group_id" => $group_id, "post_content" => $post_content, "post_time" => $post_time));
    if ($post) {
        $success = $post->commit();
        if ($success) {
            //Notify the group of students
            if ($group_id != -1) {
                $notification_users = DataObject::select_all($dao, "grouping", array("grouping_id", "user_id"), array("group_id" => $group_id));
                $notification_title = "New post in your group.";
                $notification_message = "{$user->user_name} has posted in your group.";
                $notification_link = "post/" . $post->get_primary_id();
                foreach ($notification_users as $notification_user) {
                    if ($notification_user->user_id != $user->user_id) {
                        echo notify($dao, $notification_user->user_id, $notification_title, $notification_message, $notification_link);
                    }
                }
            }
Example #9
0
 $grouping = DataObject::create($dao, "grouping", array("group_id" => $cohort->group_id, "user_id" => $user->get_primary_id()));
 $grouping->commit();
 $dao->myquery("SELECT MAX(conf_id) FROM confirmation;");
 $maxid = $dao->fetch_one();
 if ($maxid) {
     $rnd = salt(",jag,wd873423%Ed.fkug" . $maxid);
 } else {
     $rnd = salt(",jag,wd873423%Ed.fkug" . rand());
 }
 //send rnd to the user and a link which will return rnd to the server for confirmation
 $send_email = false;
 //If the confirmation has already been sent, just resend it. Don't craete a new confimation
 if (NULL != DataObject::select_one($dao, "confirmation", array("conf_id"), array("user_email" => $user_email))) {
     $send_email = true;
 } else {
     $conf = DataObject::create($dao, "confirmation", array("conf_rnd" => $rnd, "user_id" => $user->get_primary_id(), "user_email" => $user_email));
     if ($conf->commit()) {
         $send_email = true;
     } else {
         redirect("../../register/", array_merge(array("m" => "6"), $_POST));
         //This should never happen
     }
 }
 if ($send_email) {
     $subject = "Confirm your account";
     $body = "<p>Hello " . $user_name . ",</p>" . "<p>Thank you for joining Unify! Trust me, this is the best decision you've ever made.</p>" . "<p>Click <a href=\"" . $SITE_URL . "confirm.php?rnd={$rnd}\">CONFIRM</a> to confirm your account and to start using Unify.<br><br>" . "Click <a href=\"" . $SITE_URL . "unconfirm.php?rnd={$rnd}\">UNCONFIRM</a> if you have no idea why you are receiving this email." . " This will prevent this email address being used on Unify.</p>" . "<p>Best Wishes,<br>" . "The Unify Team</p>";
     $success = mail_message($user_email, $subject, $body);
     if (!$success) {
         redirect("../../register/", array_merge(array("m" => "5"), $_POST));
         //Could not send email
     } else {
Example #10
0
<?php

//Add a comment to a post on a cohort/user's feed
include "../util/session.php";
include_once "../util/mysql.php";
include "../util/status.php";
include "../notification/add.php";
$dao = new DAO(false);
$post_id = $_POST["post_id"];
$comment_content = $_POST["comment_content"];
if ($comment_content != "") {
    $comment = DataObject::create($dao, "comment", array("user_id" => $user->user_id, "post_id" => $post_id, "comment_content" => $comment_content, "comment_time" => date("Y-m-d H:i:s", time() + 3600)));
    if ($comment->commit()) {
        //Comment has been added, notifier the orignal poster
        //Find the original poster
        $post = DataObject::select_one($dao, "post", array("post_id", "user_id"), array("post_id" => $post_id));
        if ($post->user_id != $user->user_id) {
            $notification_user = $post->user_id;
            $notification_title = "New comment on your post";
            $notification_message = "{$user->user_name} has commented on one of your posts.";
            $notification_link = "post/" . $post->post_id;
            notify($dao, $notification_user, $notification_title, $notification_message, $notification_link);
        }
        echo Status::json(0, "Comment added");
    } else {
        echo Status::json(2, "Comment could not be added");
    }
} else {
    echo Status::json(1, "No comment content");
}
Example #11
0
     if ($dao->fetch_num_rows() > 0) {
         $row = $dao->fetch_one();
         $req_id = $row["req_id"];
         $lng1 = $row["lng"];
         $lng2 = $my_lng;
         $lat1 = $row["lat"];
         $lat2 = $my_lat;
         $dlng = $lng1 - $lng2;
         $distance = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($dlng));
         $distance = acos($distance);
         $distance = rad2deg($distance);
         $distance = $distance * 60 * 1.1515 * 1.609344;
         $threshold = 0.01 + 0.01;
         //20m!
         if ($distance < $threshold) {
             $new_connection = DataObject::create($dao, "connection", $connection_properties);
             $new_connection->commit();
             echo Status::json(0, "You are now unified!");
         } else {
             echo Status::json(3, "You were not close enough");
         }
         $query = "DELETE FROM friend_request WHERE req_id=\"{$req_id}\";";
         //Whether successful or not
         $dao->myquery($query);
     } else {
         $query = "INSERT INTO friend_request VALUES(NULL,\"{$user->user_id}\",\"{$selected_user->user_id}\",\"{$my_lat}\",\"{$my_lng}\");";
         $dao->myquery($query);
         echo Status::json(0, "Friend request made");
     }
 } else {
     echo Status::json(1, "You are already unified!");
Example #12
0
include "../util/status.php";
$dao = new DAO(false);
if (isset($_GET["post_id"])) {
    $post_id = $_GET["post_id"];
    $post = DataObject::select_one($dao, "post", array("post_id", "user_id"), array("post_id" => $post_id));
    if ($post) {
        if ($user->user_id == $post->user_id) {
            //User's own post, so delete it
            if ($post->delete()) {
                echo Status::json(0, "Post deleted");
            } else {
                echo Status::json(5, "Failed to delete post");
            }
        } else {
            //Not the user's own post, so hide it from them
            $hidden_post = DataObject::create($dao, "hidden_post", array("user_id" => $user->user_id, "post_id" => $post_id));
            if ($hidden_post) {
                if ($hidden_post->commit()) {
                    echo Status::json(0, "Post hidden");
                } else {
                    echo Status::json(1, "Failed to commit hidden_post");
                }
            } else {
                echo Status::json(2, "Failed to create hidden_post");
            }
        }
    } else {
        echo Status::json(3, "Failed to select post");
    }
} else {
    echo Status::json(4, "post_id not set");
Example #13
0
<?php

//Send a message in chat
include "../util/session.php";
include_once "../util/mysql.php";
include "../util/status.php";
$dao = new DAO();
$user_id = $_POST["user_id"];
$msg_content = trim($_POST["msg_content"], chr(0xc2) . chr(0xa0) . chr(0x20));
$msg_content = trim($msg_content);
if ($msg_content != "") {
    $chat_msg = DataObject::create($dao, "chat_msg", array("user_id1" => $user->user_id, "user_id2" => $user_id, "msg_content" => $msg_content));
    $chat_msg->commit();
    echo Status::json(0, "Message added");
    // {code:0,message:"message added"}
} else {
    echo Status::json(1, "No message content");
}
Example #14
0
<?php

include "../util/session.php";
include_once "../util/mysql.php";
include "../mail/send.php";
include "../util/status.php";
include "../util/constants.php";
$dao = new DAO(false);
$user_id = $_POST["user_id"];
$group_id = $_POST["group_id"];
$member = DataObject::select_one($dao, "user", array("user_id", "user_email", "user_name"), array("user_id" => $user_id));
$group = DataObject::select_one($dao, "user_group", array("group_id", "group_name"), array("group_id" => $group_id));
if ($group != NULL) {
    if ($member != NULL) {
        if (NULL == DataObject::select_one($dao, "grouping_request", array("gr_id"), array("group_id" => $group_id, "user_id" => $user_id))) {
            $body = "<p>Hello " . $member->user_name . ",</p>\n\t\t\t\t<p>" . $user->user_name . " has asked you to join the group \"" . $group->group_name . "\".\n\t\t\t\t\tIf you would like to join, please click on this link: \n\t\t\t\t\t<a href=\"" . $SITE_URL . "script/grouping/confirm.php?group_id=" . $group_id . "\">Click here to join</a>.</p>\n\t\t\t\t<p>Best Wishes,<br>The Unify Team</p>";
            $request = DataObject::create($dao, "grouping_request", array("group_id" => $group_id, "user_id" => $user_id));
            $request->commit();
            //Put the request in the database. So long as this is here, the user can accept (only when logged in)
            mail_message($member->user_email, "Group Join Request", $body);
            echo Status::json(0, "Request sent :)");
        } else {
            echo Status::json(3, "Member has already been requested to join");
        }
    } else {
        echo Status::json(1, "Member not found");
    }
} else {
    echo Status::json(2, "Group not found");
}
Example #15
0
<?php

//Add a new group, given its name and also add the user who's created it to the group
include "../util/session.php";
include_once "../util/mysql.php";
include_once "../util/redirect.php";
$group_name = $_GET["group_name"];
$dao = new DAO(false);
$group = DataObject::create($dao, "user_group", array("group_name" => $group_name));
$group->commit();
if ($group) {
    $grouping = DataObject::create($dao, "grouping", array("group_id" => $group->group_id, "user_id" => $user->user_id));
    $grouping->commit();
    if ($grouping) {
        redirect("/", array("group_id" => $grouping->group_id, "m" => "16"));
    } else {
        redirect("/?m=11");
        //Could not add you to the group after creating it!
    }
} else {
    redirect("/?m=12");
    //Could not create the group, sorry!
}
 /**
  * Returned a configured UploadField instance
  * embedded in the gridfield heard.
  *
  * @param GridField $gridField Current GridField
  *
  * @return UploadField Configured UploadField instance
  */
 public function bulkUploadField($gridField)
 {
     $fileRelationName = $this->getFileRelationName($gridField);
     $uploadField = UploadField::create($fileRelationName, '')->setForm($gridField->getForm())->setConfig('previewMaxWidth', 20)->setConfig('previewMaxHeight', 20)->setConfig('changeDetection', false)->setRecord(DataObject::create())->setTemplate('GridFieldBulkUploadField')->setDownloadTemplateName('colymba-bulkuploaddownloadtemplate')->setConfig('url', $gridField->Link('bulkupload/upload'))->setConfig('urlSelectDialog', $gridField->Link('bulkupload/select'))->setConfig('urlAttach', $gridField->Link('bulkupload/attach'))->setConfig('urlFileExists', $gridField->Link('bulkupload/fileexists'));
     //set UploadField config
     foreach ($this->ufConfig as $key => $val) {
         $uploadField->setConfig($key, $val);
     }
     //UploadField setup
     foreach ($this->ufSetup as $fn => $param) {
         $uploadField->{$fn}($param);
     }
     //UploadField Validator setup
     foreach ($this->ufValidatorSetup as $fn => $param) {
         $uploadField->getValidator()->{$fn}($param);
     }
     return $uploadField;
 }
Example #17
0
<?php

//Confirm that this user logged in wants to join the group
include "../util/session.php";
include "../util/redirect.php";
include_once "../util/mysql.php";
$group_id = $_GET["group_id"];
if (isset($user)) {
    $new_values = array("group_id" => $group_id, "user_id" => $user->user_id);
    $dao = new DAO(false);
    //Check if the user has already been added:
    $already_grouped = DataObject::select_one($dao, "grouping", array("grouping_id"), $new_values);
    if ($already_grouped == NULL) {
        $grouping = DataObject::create($dao, "grouping", $new_values);
        $request = DataObject::select_one($dao, "grouping_request", array("gr_id", "group_id", "user_id"), array("group_id" => $group_id, "user_id" => $user->user_id));
        if ($request != NULL) {
            $request->delete();
            //Delete the request from the database
            if ($grouping->commit()) {
                redirect("/", array("group_id" => $group_id, "m" => 17));
                //Send them to the new group!
            } else {
                redirect("/?m=11");
            }
        } else {
            redirect("/?m=13");
            //You have not been asked to join this group
        }
    } else {
        redirect("/", array("group_id" => $group_id, "m" => 14));
        //You are already in this group... See!