Пример #1
0
function populateTestData()
{
    dbCreateTeam(array("name" => "Team Appreciate", "number" => "2468", "type" => "FRC", "city" => "1000 Westbank Austin TX 78746", "state" => "Texas", "country" => "United States", "isActive" => true));
    dbCreateTeam(array("name" => "The Poofs", "number" => "254", "isActive" => true));
    dbCreateTeam(array("name" => "RobotTots", "number" => "118", "isActive" => true));
    dbCreateTeam(array("name" => "Katies Team", "number" => "3310", "isActive" => true));
    dbCreateProfile(array("firstName" => "Philip", "lastName" => "Liu", "bio" => "Philip Liu is a sophomore at Westlake High School. He has been highly involved with STEM programs since a young age and has developed many skills such as leadership, communication, and perseverance. In Chap Research, Philip is currently working on two different projects. The first is an all hardware project called the Chap Measuring Press (CMP) while the second is the Chap Research Outreach Management Application (CROMA). He is a member of FRC 2468 Team Appreciate and works in many sub-systems. In addition to working with the robot design, CAD, and manufacturing, he manages the documentation and portfolio for the outreach team. With all these generous opportunities, he uses his knowledge (so far) to mentor FTC teams. Outside of robotics and school, Philip practices TaeKwonDo (a soon-to-be instructor), dances, and plays football, basketball, and fantasy with his friends. In order to balance his time with a laughing and happy manner, his favorite quote is 'where there is a will, there is a way.'", "position" => "CROMA Admin", "phone" => "512-925-2241", "grade" => "10", "gender" => "Male"));
    dbCreateProfile(array("firstName" => "Parker", "lastName" => "Bergen"));
    dbCreateProfile(array("firstName" => "Rachel", "lastName" => "Gardner"));
    dbCreateProfile(array("firstName" => "Lewis", "lastName" => "Jones"));
    dbAssignUserToTeam("2", "1");
    dbAssignUserToTeam("1", "1");
    dbAssignUserToTeam("3", "1");
    dbApproveUser("1", "1");
    dbApproveUser("3", "2");
    dbApproveUser("2", "1");
    dbCreateOutreach(array("name" => "CROMA Prep", "status" => "isOutreach", "logDate" => date("Y-m-d H:i:s", time()), "TID" => "1", "address" => "my house", "description" => "An event"));
    dbCreateOutreach(array("name" => "SXSW", "status" => "isOutreach", "logDate" => time(), "address" => "my house", "description" => "An event"));
    dbCreateOutreach(array("name" => "Barnes and Nobles", "status" => "isOutreach", "logDate" => time(), "address" => "my house", "description" => "An event", "TID" => "1"));
    dbCreateOutreach(array("name" => "CROMA Prep", "status" => "isOutreach", "TID" => "1"));
    dbCreateOutreach(array("name" => "NI Week", "status" => "isIdea", "TID" => "1"));
    dbCreateOutreach(array("name" => "Robot Fair", "description" => "Promoting STEM education to the community", "type" => "Ripple Effect", "status" => "isIdea"));
    dbApproveEvent("1");
    dbAssignUserToOutreach("1", "1");
    dbAssignUserToOutreach("1", "2");
    dbAssignUserToOutreach("1", "3");
    dbAssignUserToOutreach("1", "4");
    dbAssignUserToOutreach("2", "2");
    dbLogHours(array("UID" => "1", "OID" => "1", "numberOfHours" => "12", "type" => "Pre"));
    dbLogHours(array("UID" => "2", "OID" => "1", "numberOfHours" => "15", "type" => "Post"));
    dbAddMedia(array("OID" => null, "title" => "test", "UID" => "1", "description" => "fbsjdfjsdg", "dateEntered" => time(), "link" => "https://pbs.twimg.com/profile_images/447374371917922304/P4BzupWu.jpeg"));
    dbAddMedia(array("OID" => null, "UID" => "1", "description" => "YO HOMEDAWG", "dateEntered" => time(), "link" => "http://croma.chapresearch.com/sites/default/files/CROMA%20Logo%20v1_0.png"));
    dbAddMedia(array("OID" => "1", "UID" => "1", "description" => "Ni Hao", "dateEntered" => time(), "link" => "http://chapresearch.com/wp-content/uploads/2015/08/William-e1439428977920.jpg"));
    dbAddMedia(array("OID" => "2", "description" => "Philip likes Chap Research"));
    dbAddMedia(array("OID" => null, "UID" => "1", "title" => "FUNNY"));
    dbAddEmails("1", array("*****@*****.**"));
    dbAddEmails("1", array("*****@*****.**"));
    dbAddEmails("2", array("*****@*****.**"));
    dbAddEmails("2", array("*****@*****.**"));
    dbAddTimesToOutreach(array("OID" => "1", "startTime" => "5/25/15", "endTime" => "5/26/15"));
    dbAddTimesToOutreach(array("OID" => "2", "startTime" => "1/25/15", "endTime" => "3/26/15"));
    dbAddTimesToOutreach(array("OID" => "2", "startTime" => "9/2/15", "endTime" => "11/12/15"));
    dbAddTimesToOutreach(array("OID" => "4", "startTime" => "1/3/15", "endTime" => "3/28/15"));
    dbAddNotification(array("TID" => "1", "UID" => "1", "date" => "11/10/15", "title" => "Dell Family Day", "message" => "This event will take place on Saturday, November 28th, at the J.W. Marriott hotel in Downtown Austin. We need all Robowranglers to attend."));
    dbAddNotification(array("TID" => "4", "UID" => "1", "date" => "15/4/15", "title" => "Barnes and Noble", "message" => "This event will take place on Saturday, November 7th at the Barnes and Noble in the Hill Country Galleria. See Roger Newton for details."));
    dbAddNotification(array("TID" => "3", "UID" => "1", "date" => "12/1/15", "title" => "Freescale Marathon", "message" => "Informal event... Show up on December 31st to wish the runners at the finish line a Happy New Year!"));
}
Пример #2
0
function outreachForm_submit($form, $form_state)
{
    global $user;
    $UID = $user->uid;
    $TID = $form_state['TID'];
    $outreachFields = array("name", "peopleImpacted", "address", "city", "state", "country", "status", "co_organization", "co_firstName", "co_lastName", "co_email", "co_phoneNumber", "isPublic");
    $outreachData = getFields($outreachFields, $form_state['values']);
    $outreachData = stripTags($outreachData, '');
    // remove all tags
    $outreachData['description'] = stripTags(array($form_state['values']['description']));
    // allow some tags
    $outreachData["TID"] = $TID;
    if ($form_state['new']) {
        $outreachData["UID"] = $UID;
    }
    if (isset($form_state['OID'])) {
        $OID = $form_state['OID'];
        $oldOutreachData = dbGetOutreach($OID);
        if ($outreachData["status"] == "doingWriteUp" && $oldOutreachData["isWriteUpApproved"] == true) {
            $outreachData["writeUpUID"] = null;
            $outreachData["isWriteUpSubmitted"] = 0;
            $outreachData["isWriteUpApproved"] = 0;
        }
    }
    if (!$form_state['new']) {
        // updating existing event
        $OID = $form_state['OID'];
        $result = dbUpdateOutreach($OID, $outreachData);
        if ($result) {
            // if db call was successful
            for ($i = 0; $i < $form_state['numRows']; $i++) {
                // loop through date rows
                $TOID = isset($form_state['fields']['dates']["TOID-{$i}"]) ? $form_state['fields']['dates']["TOID-{$i}"] : 0;
                $timeData['startTime'] = dbDatePHP2SQL(strtotime($form_state['values']["startTime-{$i}"]));
                dpm($timeData['startTime']);
                $timeData['endTime'] = dbDatePHP2SQL(strtotime($form_state['values']["endTime-{$i}"]));
                if ($timeData['startTime'] != null && $timeData['endTime'] != null) {
                    // if row isn't empty
                    if ($TOID != 0) {
                        // update existing record
                        dbUpdateTimesForOutreach($TOID, $timeData);
                    } else {
                        // add a new time record if there wasn't one previously
                        $timeData['OID'] = $OID;
                        dbAddTimesToOutreach($timeData);
                    }
                } else {
                    // remove time record if empty
                    dbRemoveTimeFromOutreach($TOID);
                }
            }
            for ($i = $form_state['numRows']; $i < $form_state['initialNumTimes']; $i++) {
                // executes if times were deleted
                dbRemoveTimeFromOutreach($form_state['fields']['dates']["TOID-{$i}"]);
            }
            $notification = array();
            $userName = dbGetUserName($user->uid);
            $outName = dbGetOutreachName($OID);
            $notification['dateCreated'] = dbDatePHP2SQL(time());
            $notification['dateTargeted'] = dbDatePHP2SQL(time());
            $notification['message'] = "{$userName} has updated outreach {$outName}.";
            $notification['bttnTitle'] = 'View';
            $notification['bttnLink'] = '?q=viewOutreach&OID=' . $OID;
            $notification['TID'] = $TID;
            notifyUsersByRole($notification, 'moderator');
            // handle tags
            if (!empty($form_state['values']['tags'])) {
                $newTags = $form_state['values']['tags'];
                $previous = dbGetTagsForOutreach($OID, true);
                // the "true" means this will return only OTID's
                if ($previous == false) {
                    // if there aren't any tags
                    $previous = array();
                }
                $deleted = array_diff($previous, $newTags);
                $added = array_diff($newTags, $previous);
                foreach ($deleted as $delete) {
                    // $delete is the OTID to be removed from the outreach
                    if (!empty($delete)) {
                        dbRemoveTagFromOutreach($delete, $OID);
                    }
                }
                foreach ($added as $add) {
                    // $add is the OTID to be added to the outreach
                    if (!empty($add)) {
                        dbAddTagToOutreach($add, $OID);
                    }
                }
            }
            drupal_set_message("Outreach updated!");
        } else {
            drupal_set_message("Outreach not updated.");
        }
    } else {
        // adding new event
        $outreachData['logDate'] = dbDatePHP2SQL(time());
        $OID = dbCreateOutreach($outreachData);
        if ($OID != false) {
            dbAddUserAsOwnerOfOutreach($UID, $OID);
            dbAssignUserToOutreach($UID, $OID, 'owner');
            // handle times
            if ($outreachData['status'] != 'isIdea') {
                for ($i = 0; $i < $form_state['numRows']; $i++) {
                    $time = array("startTime-{$i}", "endTime-{$i}");
                    $timeData = getFields($time, $form_state['values']);
                    if ($timeData["startTime-{$i}"] != null && $timeData["endTime-{$i}"] != null) {
                        // rename array keys to match columns
                        $timeData['startTime'] = dbDatePHP2SQL(strtotime($timeData["startTime-{$i}"]));
                        $timeData['endTime'] = dbDatePHP2SQL(strtotime($timeData["endTime-{$i}"]));
                        unset($timeData["endTime-{$i}"], $timeData["startTime-{$i}"]);
                        $timeData['OID'] = $OID;
                        dbAddTimesToOutreach($timeData);
                    }
                }
            }
            // handle tags
            if (!empty($form_state['values']['tags'])) {
                foreach ($form_state['values']['tags'] as $OTID) {
                    dbAddTagToOutreach($OTID, $OID);
                }
            }
            // create notification
            $notification = array();
            $userName = dbGetUserName($user->uid);
            $outName = dbGetOutreachName($OID);
            $notification['dateCreated'] = dbDatePHP2SQL(time());
            $notification['dateTargeted'] = dbDatePHP2SQL(time());
            $notification['message'] = "{$userName} has created outreach {$outName}.";
            $notification['bttnTitle'] = 'View';
            $notification['bttnLink'] = '?q=viewOutreach&OID=' . $OID;
            $notification['TID'] = $TID;
            notifyUsersByRole($notification, 'moderator');
            drupal_set_message("Outreach created!");
        } else {
            // if the $OID IS false
            form_set_error("Outreach not created successfully");
        }
    }
    if (dbIsOutreachOver($OID)) {
        drupal_set_message("It appears you are logging an old event. Don't forget to <a href=\"?q=logHours&OID={$OID}\"><b>log old hours</b></a>!");
    }
    drupal_goto('viewOutreach', array('query' => array('OID' => $OID)));
}