function find_by_criteria($module, $id_in_module = null, $type = null, $identifier = null, $poster_id = null, $fixer_id = null)
 {
     global $Sql;
     $criterias = array();
     if (empty($module) || !is_string($module)) {
         return array();
     }
     $criterias[] = "module = '" . strprotect($module) . "'";
     if ($id_in_module != null) {
         $criterias[] = "id_in_module = '" . intval($id_in_module) . "'";
     }
     if ($type != null) {
         $criterias[] = "type = '" . strprotect($type) . "'";
     }
     if ($identifier != null) {
         $criterias[] = "identifier = '" . strprotect($identifier) . "'";
     }
     if ($poster_id != null) {
         $criterias[] = "poster_id = '" . intval($poster_id) . "'";
     }
     if ($fixer_id != null) {
         $criterias[] = "fixer_id = '" . intval($fixer_id) . "'";
     }
     $array_result = array();
     $where_clause = "contribution_type = '" . CONTRIBUTION_TYPE . "' AND " . implode($criterias, " AND ");
     $result = $Sql->query_while("SELECT id, entitled, fixing_url, auth, current_status, module, creation_date, fixing_date, poster_id, fixer_id, poster_member.login poster_login, fixer_member.login fixer_login, identifier, id_in_module, type, description\n\t\tFROM " . DB_TABLE_EVENTS . " c\n\t\tLEFT JOIN " . DB_TABLE_MEMBER . " poster_member ON poster_member.user_id = c.poster_id\n\t\tLEFT JOIN " . DB_TABLE_MEMBER . " fixer_member ON fixer_member.user_id = c.fixer_id\n\t\tWHERE " . $where_clause, __LINE__, __FILE__);
     while ($row = $Sql->fetch_assoc($result)) {
         $contri = new Contribution();
         $contri->build($row['id'], $row['entitled'], $row['description'], $row['fixing_url'], $row['module'], $row['current_status'], new Date(DATE_TIMESTAMP, TIMEZONE_SYSTEM, $row['creation_date']), new Date(DATE_TIMESTAMP, TIMEZONE_SYSTEM, $row['fixing_date']), unserialize($row['auth']), $row['poster_id'], $row['fixer_id'], $row['id_in_module'], $row['identifier'], $row['type'], $row['poster_login'], $row['fixer_login']);
         $array_result[] = $contri;
     }
     return $array_result;
 }
 public function execute(HTTPRequestCustom $request)
 {
     $id = $request->get_getint('id', 0);
     if (!empty($id) && AppContext::get_current_user()->check_level(User::MEMBER_LEVEL)) {
         try {
             $this->downloadfile = DownloadService::get_downloadfile('WHERE download.id = :id', array('id' => $id));
         } catch (RowNotFoundException $e) {
             $error_controller = PHPBoostErrors::unexisting_page();
             DispatchManager::redirect($error_controller);
         }
     }
     if ($this->downloadfile !== null && $this->downloadfile->is_visible()) {
         if (!PersistenceContext::get_querier()->row_exists(PREFIX . 'events', 'WHERE id_in_module=:id_in_module AND module=\'download\' AND current_status = 0', array('id_in_module' => $this->downloadfile->get_id()))) {
             $contribution = new Contribution();
             $contribution->set_id_in_module($this->downloadfile->get_id());
             $contribution->set_entitled(StringVars::replace_vars(LangLoader::get_message('contribution.deadlink', 'common'), array('link_name' => $this->downloadfile->get_name())));
             $contribution->set_fixing_url(DownloadUrlBuilder::edit($this->downloadfile->get_id())->relative());
             $contribution->set_description(LangLoader::get_message('contribution.deadlink_explain', 'common'));
             $contribution->set_poster_id(AppContext::get_current_user()->get_id());
             $contribution->set_module('download');
             $contribution->set_type('alert');
             $contribution->set_auth(Authorizations::capture_and_shift_bit_auth(DownloadService::get_categories_manager()->get_heritated_authorizations($this->downloadfile->get_id_category(), Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT));
             ContributionService::save_contribution($contribution);
         }
         DispatchManager::redirect(new UserContributionSuccessController());
     } else {
         $error_controller = PHPBoostErrors::unexisting_page();
         DispatchManager::redirect($error_controller);
     }
 }
 public static function save_contribution($cid, $uid, $title, $body, $track, $tags, $ccid = 0, $is_active = 1, $display_on = 0, $is_default_content = FALSE)
 {
     // global var $path_prefix has been removed - please, use PA::$path static variable
     $errors = array();
     // ensure integers here
     $cid = (int) $cid;
     $uid = (int) $uid;
     $ccid = (int) $ccid;
     // if a new post, make one, otherwise load the existing one
     if ($cid) {
         $post = Content::load_content($cid, $uid);
         // ignore $ccid passed to function if the post already exists
         // - we don't allow users to move posts between
         // ContentCollections.
         $ccid = (int) $post->parent_collection_id;
     } else {
         $post = new Contribution();
         $post->author_id = $uid;
         if ($ccid) {
             $post->parent_collection_id = $ccid;
         }
     }
     if ($ccid && $ccid != -1) {
         $g = ContentCollection::load_collection($ccid, $uid);
         $g->assert_user_access($uid);
     } else {
         $g = NULL;
     }
     $post->title = $title;
     $post->body = $body;
     $post->allow_comments = 1;
     $post->is_active = $is_active;
     $post->display_on = $display_on;
     $post->trackbacks = '';
     if ($track) {
         $post->trackbacks = implode(",", $track);
     }
     $post->is_default_content = $is_default_content;
     $post->save();
     Tag::add_tags_to_content($post->content_id, $tags);
     if ($track) {
         foreach ($track as $t) {
             if (!$post->send_trackback($t)) {
                 $errors[] = array("code" => "trackback_failed", "msg" => "Failed to send trackback", "url" => $t);
             }
         }
     }
     if ($g && !$cid) {
         // new post - post it to the group as well
         $g->post_content($post->content_id, $uid);
     }
     return array("cid" => (int) $post->content_id, "moderation_required" => $g ? $g->is_moderated == 1 && $g->author_id != $uid : FALSE, "errors" => $errors);
 }
 public static function get(User $user)
 {
     global $db;
     $user_id = $user->getID();
     $query = "SELECT * FROM `student_contributions` WHERE `user_id` = " . $db->qstr($user_id) . " ORDER BY `start_year` DESC, `start_month` DESC";
     $results = $db->getAll($query);
     $contributions = array();
     if ($results) {
         foreach ($results as $result) {
             $contribution = Contribution::fromArray($result);
             $contributions[] = $contribution;
         }
     }
     return new self($contributions);
 }
function sendThankyouMail(Contribution $contribution)
{
    $name = $contribution->getName();
    $pName = $contribution->getPoiName();
    $add = $contribution->getPoiAddress();
    $cat = $contribution->getPoiCategory();
    $mes = $contribution->getPoiMessage();
    $subject = "Thank you for your Contribution ({$pName})";
    $message = "\n                <html>\n                <head>\n                <title>Feedback Received</title>\n                </head>\n                <body>\n                <img src='http://mymap.com.np/img/banner.jpg'><br>\n                <p>Dear {$name},</p>\n                <p>Your following contributionhas been received and acknowledged.</p>\n                <p><b>POI Name : </b>{$pName}</p>\n                <p><b>POI Address : </b>{$add}</p>\n                <p><b>POI Category : </b>{$cat}</p>\n                <p><b>Message : </b>{$mes}</p>\n                <p>Your contribution will be processed and will be available in the next update. Thank you for your contribution!</p>\n                <p>Regards, </p>\n                <p><a href='http://mymap.com.np'>MyMap - Offline map for Nepal </a> developers.</p>\n                </body>\n                </html>\n                ";
    $message = str_replace("\n.", "\n..", $message);
    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    // More headers
    $headers .= 'From: <*****@*****.**>' . "\r\n";
    mail($contribution->getEmail(), $subject, $message, $headers);
}
 function do_updates()
 {
     // ALL DATABASE UPDATES GO IN HERE!
     // FOR EACH SQL STATEMENT YOU WANT TO EXECUTE, GIVE IT A 'KEY', THEN CALL:
     // $this->qup("key", "sql statement");
     // eg. $this->qup("new foobar table", "create table foobar (id int not null, primary key(id))");
     // YOU SHOULD NORMALLY PUT YOUR UPDATES AT THE *END* OF THIS FUNCTION.
     /** NOTE: KEY must be unique for each update query */
     /** EXAMPLE ADD NEW TABLE */
     /*
     $this->qup("new mc_feeds table",
                  "CREATE TABLE mc_feeds (
                  user_id int not null,
                  id int not null auto_increment,
                  primary key(user_id,id),
                  feed_url text not null,
                  feed_name varchar(255)
     )"); 
     */
     /** EXAMPLE ALTER TABLE */
     // $this->qup("add feed_description to mc_feeds", "ALTER TABLE mc_feeds ADD COLUMN feed_description TEXT");
     /** EXAMPLE INSERT INTO TABLE */
     // $this->qup("insert default data 1 for relation classifications", "INSERT INTO `relation_classifications` (`relation_type`, `relation_type_id`) VALUES ('acquaintance', '1');");
     /** EXAMPLE UPDATE TABLE */
     // $this->qup("changed id field in review-type movie", "UPDATE review_type SET review_id = 1 WHERE review_name = 'Movie'");
     // finally, run the 'safe' updates in net_extra.php.
     $child_role = array('id' => 9, 'name' => 'Child', 'description' => 'Role for family members with Child status', 'read_only' => 1, 'type' => 'group', 'tasks' => array(12, 13, 15, 16, 22, 30));
     $this->qup_all_networks("2009-09-28, by: Zoran Hron - adding Child role, ID: " . $child_role['id'], "INSERT INTO {roles} (id, name, description, created, changed, read_only, type)\n                                 VALUES (" . $child_role['id'] . ", '" . $child_role['name'] . "', '" . $child_role['description'] . "', " . time() . ", " . time() . ", " . $child_role['read_only'] . ", '" . $child_role['type'] . "')\n                                 ON DUPLICATE KEY UPDATE name = '" . $child_role['name'] . "', description = '" . $child_role['description'] . "', read_only = " . $child_role['read_only'] . ", type = '" . $child_role['type'] . "'");
     foreach ($child_role['tasks'] as $task_id) {
         $this->qup_all_networks("2009-09-28, by: Zoran Hron - adding tasks/permissions for Child role. ID=" . $child_role['id'] . ", task ID=" . $task_id, "INSERT IGNORE INTO {tasks_roles} (`task_id`, `role_id`) VALUES (" . $task_id . ", " . $child_role['id'] . ");");
     }
     require_once 'api/Contribution/Contribution.php';
     if (!Contribution::table_exists()) {
         $this->qup('2010-11-19, by: Jonathan Knapp - adding cc_contributions table to database', "CREATE  TABLE `cc_contributions` ( `content_id` INT NOT NULL , `contribution_id` INT NOT NULL , `type` ENUM('issue','conversation') NOT NULL , `title` TEXT , PRIMARY KEY (`content_id`) );");
     }
     $this->run_xml_updates();
     run_net_extra();
 }
Beispiel #7
0
         if (count($corresponding_contributions) > 0) {
             $media_contribution = $corresponding_contributions[0];
             $media_contribution->set_status(Event::EVENT_STATUS_PROCESSED);
             ContributionService::save_contribution($media_contribution);
         }
     }
     // Feeds Regeneration
     Feed::clear_cache('media');
     AppContext::get_response()->redirect('media' . url('.php?id=' . $media['idedit']));
 } elseif (!$media['idedit'] && (($auth_write = MediaAuthorizationsService::check_authorizations($media['idcat'])->write()) || MediaAuthorizationsService::check_authorizations($media['idcat'])->contribution())) {
     $result = PersistenceContext::get_querier()->insert(PREFIX . "media", array('idcat' => $media['idcat'], 'iduser' => AppContext::get_current_user()->get_id(), 'timestamp' => time(), 'name' => $media['name'], 'contents' => FormatingHelper::strparse($media['contents']), 'url' => $media['url'], 'mime_type' => $media['mime_type'], 'infos' => MediaAuthorizationsService::check_authorizations($media['idcat'])->write() ? MEDIA_STATUS_APROBED : 0, 'width' => $media['width'], 'height' => $media['height']));
     $new_id_media = $result->get_last_inserted_id();
     // Feeds Regeneration
     Feed::clear_cache('media');
     if (!$auth_write) {
         $media_contribution = new Contribution();
         $media_contribution->set_id_in_module($new_id_media);
         $media_contribution->set_description(stripslashes($media['counterpart']));
         $media_contribution->set_entitled($media['name']);
         $media_contribution->set_fixing_url('/media/media_action.php?edit=' . $new_id_media);
         $media_contribution->set_poster_id(AppContext::get_current_user()->get_id());
         $media_contribution->set_module('media');
         $media_contribution->set_auth(Authorizations::capture_and_shift_bit_auth(MediaService::get_categories_manager()->get_heritated_authorizations($media['idcat'], Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT));
         ContributionService::save_contribution($media_contribution);
         DispatchManager::redirect(new UserContributionSuccessController());
     } else {
         AppContext::get_response()->redirect('media' . url('.php?id=' . $new_id_media));
     }
 } else {
     $error_controller = PHPBoostErrors::user_not_authorized();
     DispatchManager::redirect($error_controller);
Beispiel #8
0
             }
             break;
         case 1:
             list($start_timestamp, $end_timestamp) = array(0, 0);
             break;
         default:
             list($visible, $start_timestamp, $end_timestamp) = array(0, 0, 0);
     }
     import('util/url');
     $file_relative_url = new Url($file_url);
     $Sql->query_inject("INSERT INTO " . PREFIX . "download (title, idcat, url, size, count, force_download, contents, short_contents, image, timestamp, release_timestamp, start, end, visible, approved, users_note) " . "VALUES ('" . $file_title . "', '" . $file_cat_id . "', '" . $file_relative_url->relative() . "', '" . $file_size . "', '" . $file_hits . "', '" . ($file_download_method == 'force_download' ? DOWNLOAD_FORCE_DL : DOWNLOAD_REDIRECT) . "', '" . strparse($file_contents) . "', '" . strparse($file_short_contents) . "', '" . $file_image . "', '" . $file_creation_date->get_timestamp() . "', '" . ($ignore_release_date ? 0 : $file_release_date->get_timestamp()) . "', '" . $start_timestamp . "', '" . $end_timestamp . "', '" . $visible . "', '" . (int) $auth_write . "', '')", __LINE__, __FILE__);
     $new_id_file = $Sql->insert_id("SELECT MAX(id) FROM " . PREFIX . "download");
     if (!$auth_write) {
         import('events/contribution');
         import('events/contribution_service');
         $download_contribution = new Contribution();
         $download_contribution->set_id_in_module($new_id_file);
         $download_contribution->set_description(stripslashes($contribution_counterpart));
         $download_contribution->set_entitled(sprintf($DOWNLOAD_LANG['contribution_entitled'], $file_title));
         $download_contribution->set_fixing_url('/download/management.php?edit=' . $new_id_file);
         $download_contribution->set_poster_id($User->get_attribute('user_id'));
         $download_contribution->set_module('download');
         $download_contribution->set_auth(Authorizations::capture_and_shift_bit_auth(Authorizations::merge_auth($CONFIG_DOWNLOAD['global_auth'], $download_categories->compute_heritated_auth($file_cat_id, DOWNLOAD_WRITE_CAT_AUTH_BIT, AUTH_CHILD_PRIORITY), DOWNLOAD_WRITE_CAT_AUTH_BIT, AUTH_CHILD_PRIORITY), DOWNLOAD_WRITE_CAT_AUTH_BIT, CONTRIBUTION_AUTH_BIT));
         ContributionService::save_contribution($download_contribution);
         redirect(HOST . DIR . '/download/contribution.php');
     }
     $download_categories->Recount_sub_files();
     import('content/syndication/feed');
     Feed::clear_cache('download');
     redirect(HOST . DIR . '/download/' . url('download.php?id=' . $new_id_file, 'download-' . $new_id_file . '+' . url_encode_rewrite($file_title) . '.php'));
 } else {
 /**
  * Remove the specified contribution from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Contribution::destroy($id);
     return Redirect::route('contributions.index');
 }
Beispiel #10
0
 function Alert_topic($alert_post, $alert_title, $alert_contents)
 {
     global $Sql, $User, $CAT_FORUM, $LANG;
     $topic_infos = $Sql->query_array(PREFIX . "forum_topics", "idcat", "title", "WHERE id = '" . $alert_post . "'", __LINE__, __FILE__);
     $Sql->query_inject("INSERT INTO " . PREFIX . "forum_alerts (idcat, idtopic, title, contents, user_id, status, idmodo, timestamp) VALUES ('" . $topic_infos['idcat'] . "', '" . $alert_post . "', '" . $alert_title . "', '" . $alert_contents . "', '" . $User->get_attribute('user_id') . "', 0, 0, '" . time() . "')", __LINE__, __FILE__);
     $alert_id = $Sql->insert_id("SELECT MAX(id) FROM " . PREFIX . "forum_alerts");
     import('events/contribution');
     import('events/contribution_service');
     $contribution = new Contribution();
     $contribution->set_id_in_module($alert_id);
     $contribution->set_entitled(sprintf($LANG['contribution_alert_moderators_for_topics'], stripslashes($alert_title)));
     $contribution->set_fixing_url('/forum/moderation_forum.php?action=alert&id=' . $alert_id);
     $contribution->set_description(stripslashes($alert_contents));
     $contribution->set_poster_id($User->get_attribute('user_id'));
     $contribution->set_module('forum');
     $contribution->set_type('alert');
     $contribution->set_auth(Authorizations::capture_and_shift_bit_auth($CAT_FORUM[$topic_infos['idcat']]['auth'], EDIT_CAT_FORUM, CONTRIBUTION_AUTH_BIT));
     ContributionService::save_contribution($contribution);
 }
function route2groups()
{
    global $user, $is_edit;
    $extra = unserialize(PA::$network_info->extra);
    $tags = preg_split('/\\s*,\\s*/', strtolower($_POST['tags']));
    $tags = array_unique($tags);
    $net_owner = new User();
    $net_owner->load((int) PA::$network_info->owner_id);
    $valid_post_types = array('BlogPost', 'Contribution', 'Suggestion');
    $type = isset($_POST) && isset($_POST['blog_type']) && in_array($_POST['blog_type'], $valid_post_types) ? $_POST['blog_type'] : 'BlogPost';
    //find tag entry
    $terms = array();
    foreach ($tags as $term) {
        $tr = trim($term);
        if ($tr) {
            $terms[] = $tr;
        }
    }
    if (!empty($_POST['route_to_pa_home']) && $_POST['route_to_pa_home'] == 1) {
        $display_on_homepage = DISPLAY_ON_HOMEPAGE;
        //its zero
    } else {
        $display_on_homepage = NO_DISPLAY_ON_HOMEPAGE;
        //This will not show up on homepage - flag has opposite values
    }
    if (is_array($_POST['route_targets_group'])) {
        if (in_array(-2, $_POST['route_targets_group'])) {
            //-2 means Select none of group
            // no need to post in any group
        } elseif (in_array(-1, $_POST['route_targets_group'])) {
            //-1 means select all the groups
            // post in all the groups
            $group_array = explode(',', $_POST['Allgroups']);
            foreach ($group_array as $gid) {
                // post to all the groups
                $_group = Group::load_group_by_id((int) $gid);
                $login_required_str = null;
                if ($_group->access_type == ACCESS_PRIVATE) {
                    $login_required_str = '&login_required=true';
                }
                switch ($type) {
                    case 'BlogPost':
                    default:
                        $res = BlogPost::save_blogpost(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage);
                        break;
                    case 'Contribution':
                        $res = Contribution::save_contribution(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage);
                        break;
                    case 'Suggestion':
                        $res = Suggetion::save_suggestion(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage);
                        break;
                }
                $permalink_cid = $res['cid'];
                // NOTE: would this notification message be sent for each group ???
                $content_obj = Content::load_content((int) $permalink_cid);
                PANotify::send("content_posted", PA::$network_info, $user, $content_obj);
                // notify network owner (maybe group owner would be better?)
                if ($display_on_homepage == DISPLAY_ON_HOMEPAGE) {
                    PANotify::send("content_posted_to_comm_blog", PA::$network_info, $user, $content_obj);
                }
                //-------
                //for rivers of people
                $activity = 'group_post_a_blog';
                $activity_extra['info'] = $user->first_name . 'posted a new blog';
                $activity_extra['blog_name'] = $_POST["blog_title"];
                $activity_extra['blog_id'] = $permalink_cid;
                $activity_extra['blog_url'] = PA::$url . PA_ROUTE_CONTENT . '/cid=' . $permalink_cid . $login_required_str;
                $extra = serialize($activity_extra);
                $object = $gid;
                // update status to unverified
                $group = ContentCollection::load_collection((int) $gid, PA::$login_uid);
                if ($group->reg_type == REG_MODERATED) {
                    Network::moderate_network_content((int) $gid, $permalink_cid);
                } else {
                    if ($extra['network_content_moderation'] == NET_YES && $is_edit == 0 && PA::$network_info->owner_id != $user->user_id) {
                        Network::moderate_network_content($gid, $permalink_cid);
                    }
                }
                if (!PA::is_moderated_content() && $group->reg_type != REG_MODERATED) {
                    //Write to activity log only when moderation is off
                    Activities::save($user->user_id, $activity, $object, $extra);
                }
            }
        } else {
            // post in selected groups
            foreach ($_POST['route_targets_group'] as $gid) {
                //only send to selected groups
                $_group = Group::load_group_by_id((int) $gid);
                $login_required_str = null;
                if ($_group->access_type == ACCESS_PRIVATE) {
                    $login_required_str = '&login_required=true';
                }
                switch ($type) {
                    case 'BlogPost':
                    default:
                        $res = BlogPost::save_blogpost(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage);
                        break;
                    case 'Contribution':
                        $res = Contribution::save_contribution(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage);
                        break;
                    case 'Suggestion':
                        $res = Suggestion::save_suggestion(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage);
                        break;
                }
                $permalink_cid = $res['cid'];
                $content_obj = Content::load_content((int) $permalink_cid);
                PANotify::send("content_posted", PA::$network_info, $user, $content_obj);
                // notify network owner (maybe group owner would be better?)
                if ($display_on_homepage == DISPLAY_ON_HOMEPAGE) {
                    PANotify::send("content_posted_to_comm_blog", PA::$network_info, $user, $content_obj);
                }
                //for rivers of people
                $activity = 'group_post_a_blog';
                $activity_extra['info'] = $user->first_name . 'posted a new blog';
                $activity_extra['blog_name'] = $_POST["blog_title"];
                $activity_extra['blog_id'] = $permalink_cid;
                $activity_extra['blog_url'] = PA::$url . PA_ROUTE_CONTENT . '/cid=' . $permalink_cid . $login_required_str;
                $extra = serialize($activity_extra);
                $object = $gid;
                // update status to unverified
                $group = ContentCollection::load_collection((int) $gid, PA::$login_uid);
                if ($group->reg_type == REG_MODERATED) {
                    Network::moderate_network_content((int) $gid, $permalink_cid);
                } else {
                    if ($extra['network_content_moderation'] == NET_YES && $is_edit == 0 && PA::$network_info->owner_id != $user->user_id) {
                        Network::moderate_network_content($gid, $permalink_cid);
                    }
                }
                if (!PA::is_moderated_content() && $group->reg_type != REG_MODERATED) {
                    //Write to activity log only when moderation is off
                    Activities::save($user->user_id, $activity, $object, $extra);
                }
            }
        }
    }
    return TRUE;
}
 public function postfund($id)
 {
     $billing = App::make('Acme\\Billing\\BillingInterface');
     $billing->charge(['email' => Input::get('email'), 'token' => Input::get('stripe-token')]);
     $contribution = new Contribution();
     $contribution->user_id = Auth::user()->user_id;
     $contribution->pitch_id = $id;
     $contribution->amount = '20';
     $contribution->save();
     return Redirect::action('PitchesController@show', [$id]);
 }
     //its zero
 } else {
     $display_on_homepage = NO_DISPLAY_ON_HOMEPAGE;
     //This will not show up on homepage - flag has opposite values
 }
 $ccid = -1;
 if (!empty(PA::$config->simple['omit_routing'])) {
     $ccid = !empty($_REQUEST['ccid']) ? $_REQUEST['ccid'] : -1;
 }
 switch ($type) {
     case 'BlogPost':
     default:
         $post_saved = BlogPost::save_blogpost(0, PA::$login_uid, $_POST["blog_title"], $_POST["description"], NULL, $terms, $ccid, 1, $display_on_homepage);
         break;
     case 'Contribution':
         $post_saved = Contribution::save_contribution(0, PA::$login_uid, $_POST["blog_title"], $_POST["description"], NULL, $terms, $ccid, 1, $display_on_homepage);
         if ($type == 'Contribution' && $redirect != '') {
             $url_parts = parse_url($redirect);
             parse_str($url_parts['query'], $query_args);
             // save extra information about CC Contributions
             $contribution_id = null;
             $contribution_type = null;
             $contribution_title = null;
             if (isset($query_args['conversation_id'])) {
                 $contribution_type = 'conversation';
                 $contribution_id = $query_args['conversation_id'];
             }
             if (isset($query_args['issue_id'])) {
                 $contribution_type = 'issue';
                 $contribution_id = $query_args['issue_id'];
             }
 /**
  * @param $row
  *      the row from the database
  * @return Contribution
  *      the contribution object
  */
 public function parseContributions($row)
 {
     $contribution = new Contribution();
     $contribution->initWithId($row['id'], $row['name'], $row['email'], $row['poiName'], $row['poiAddress'], $row['poiCategory'], $row['poiMessage'], $row['poiRequest'], $row['status'], $row['date']);
     return $contribution;
 }
Beispiel #15
0
             ContributionService::save_contribution($media_contribution);
         }
     }
     import('content/syndication/feed');
     Feed::clear_cache('media');
     redirect_confirm('media' . url('.php?id=' . $media['idedit']), $MEDIA_LANG['edit_success'], TIME_REDIRECT);
 } elseif (!$media['idedit'] && (($auth_write = $User->check_auth($auth_cat, MEDIA_AUTH_WRITE)) || $User->check_auth($auth_cat, MEDIA_AUTH_CONTRIBUTION))) {
     $Sql->query_inject("INSERT INTO " . PREFIX . "media (idcat, iduser, timestamp, name, contents, url, mime_type, infos, width, height, users_note) VALUES ('" . $media['idcat'] . "', '" . $User->Get_attribute('user_id') . "', '" . time() . "', '" . $media['name'] . "', '" . strparse($media['contents']) . "', '" . $media['url'] . "', '" . $media['mime_type'] . "', " . "'" . ($User->check_auth($auth_cat, MEDIA_AUTH_WRITE) ? MEDIA_STATUS_APROBED : 0) . "', '" . $media['width'] . "', '" . $media['height'] . "', '')", __LINE__, __FILE__);
     $new_id_media = $Sql->insert_id("SELECT MAX(id) FROM " . PREFIX . "media");
     $media_categories->recount_media_per_cat($media['idcat']);
     import('content/syndication/feed');
     Feed::clear_cache('media');
     if (!$auth_write) {
         import('events/contribution');
         import('events/contribution_service');
         $media_contribution = new Contribution();
         $media_contribution->set_id_in_module($new_id_media);
         $media_contribution->set_description(stripslashes($media['counterpart']));
         $media_contribution->set_entitled(stripslashes(sprintf($MEDIA_LANG['contribution_entitled'], $media['name'])));
         $media_contribution->set_fixing_url('/media/media_action.php?edit=' . $new_id_media);
         $media_contribution->set_poster_id($User->get_attribute('user_id'));
         $media_contribution->set_module('media');
         $media_contribution->set_auth(Authorizations::capture_and_shift_bit_auth(Authorizations::merge_auth($MEDIA_CATS[0]['auth'], $media_categories->compute_heritated_auth($media['idcat'], MEDIA_AUTH_WRITE, AUTH_CHILD_PRIORITY), MEDIA_AUTH_WRITE, AUTH_CHILD_PRIORITY), MEDIA_AUTH_WRITE, CONTRIBUTION_AUTH_BIT));
         ContributionService::save_contribution($media_contribution);
         redirect(HOST . DIR . '/media/contribution.php?cat=' . $media['idcat']);
     } else {
         redirect_confirm('media' . url('.php?id=' . $new_id_media), $MEDIA_LANG['add_success'], TIME_REDIRECT);
     }
 } else {
     $Errorh->handler('e_auth', E_USER_REDIRECT);
     exit;
 /**
  * @desc Deletes a contribution in the database.
  * @param Contribution $contribution The contribution to delete in the data base.
  */
 public static function delete_contribution($contribution)
 {
     //If it exists in database
     if ($contribution->get_id() > 0) {
         self::$db_querier->delete(DB_TABLE_EVENTS, 'WHERE id = :id', array('id' => $contribution->get_id()));
         //We reset the id
         $contribution->set_id(0);
         //Regeneration of the member cache file
         UnreadContributionsCache::invalidate();
     }
 }
function get_mspr_entity($type, $entity_id)
{
    switch ($type) {
        case 'studentships':
            $entity = Studentship::get($entity_id);
            break;
        case 'clineval':
            $entity = ClinicalPerformanceEvaluation::get($entity_id);
            break;
        case 'internal_awards':
            $entity = InternalAwardReceipt::get($entity_id);
            break;
        case 'external_awards':
            $entity = ExternalAwardReceipt::get($entity_id);
            break;
        case 'contributions':
            $entity = Contribution::get($entity_id);
            break;
        case 'student_run_electives':
            $entity = StudentRunElective::get($entity_id);
            break;
        case 'observerships':
            $entity = Observership::get($entity_id);
            break;
        case 'int_acts':
            $entity = InternationalActivity::get($entity_id);
            break;
        case 'critical_enquiry':
            $entity = CriticalEnquiry::get($entity_id);
            break;
        case 'community_based_project':
            $entity = CommunityBasedProject::get($entity_id);
            break;
        case 'research_citations':
            $entity = ResearchCitation::get($entity_id);
            break;
    }
    return $entity;
}
 public function process()
 {
     $user = $this->_user;
     $translator = $this->_translator;
     $type = $this->type;
     static $valid = array("external_awards" => array("add", "remove", "edit"), "contributions" => array("add", "remove", "edit"), "critical_enquiry" => array("add", "remove", "edit"), "community_based_project" => array("add", "remove", "edit"), "research_citations" => array("add", "remove", "edit", "resequence"), "observerships" => array("add", "remove", "edit", "resequence"));
     $section = filter_input(INPUT_GET, 'mspr-section', FILTER_CALLBACK, array('options' => 'strtolower'));
     if ($section) {
         $params = array('entity_id' => FILTER_VALIDATE_INT, 'action' => array('filter' => FILTER_CALLBACK, 'options' => 'strtolower'), 'user_id' => FILTER_VALIDATE_INT);
         $inputs = filter_input_array(INPUT_POST, $params);
         extract($inputs);
         if (!$action) {
             add_error($translator->translate("mspr_no_action"));
         }
         if (!array_key_exists($section, $valid)) {
             add_error($translator->translate("mspr_invalid_section"));
         } else {
             if (!in_array($action, $valid[$section])) {
                 add_error($translator->translate("mspr_invalid_action"));
             }
         }
         if (!has_error() && in_array($action, array("add", "edit", "resequence"))) {
             $inputs = get_mspr_inputs($section);
             process_mspr_inputs($section, $inputs, $translator);
             //modifies inputs/adds errors
         }
         if (!has_error()) {
             $inputs['user_id'] = $user_id;
             if ($action == "add") {
                 switch ($section) {
                     case 'external_awards':
                         ExternalAwardReceipt::create($inputs);
                         break;
                     case 'contributions':
                         Contribution::create($inputs);
                         break;
                     case 'critical_enquiry':
                         if (CriticalEnquiry::get($user_id)) {
                             add_error($translator->translate("mspr_too_many_critical_enquiry"));
                         } else {
                             CriticalEnquiry::create($inputs);
                         }
                         break;
                     case 'community_based_project':
                         if (CommunityBasedProject::get($user_id)) {
                             add_error($translator->translate("mspr_too_many_community_based_project"));
                         } else {
                             CommunityBasedProject::create($inputs);
                         }
                         break;
                     case 'research_citations':
                         ResearchCitation::create($inputs);
                         break;
                     case 'observerships':
                         $observership = Observership::create($inputs);
                         break;
                 }
             } elseif ($action == "resequence") {
                 switch ($section) {
                     case 'research_citations':
                         ResearchCitations::setSequence($user_id, $inputs['research_citations']);
                         break;
                 }
             } else {
                 //everything else requires an entity
                 if ($entity_id) {
                     $entity = get_mspr_entity($section, $entity_id);
                     if ($entity) {
                         switch ($action) {
                             case "remove":
                                 $entity->delete();
                                 break;
                             case "edit":
                                 if ($entity instanceof Approvable) {
                                     $inputs['comment'] = "";
                                     $inputs['status'] = 0;
                                     //set to unapproved.
                                 }
                                 $entity->update($inputs);
                                 //inputs processed above
                                 break;
                         }
                     } else {
                         add_error($translator->translate("mspr_invalid_entity"));
                     }
                 } else {
                     add_error($translator->translate("mspr_no_entity"));
                 }
             }
         }
         switch ($section) {
             case 'external_awards':
                 $external_awards = ExternalAwardReceipts::get($user);
                 display_status_messages();
                 echo display_external_awards($external_awards, $type);
                 break;
             case 'contributions':
                 $contributions = Contributions::get($user);
                 display_status_messages();
                 echo display_contributions($contributions, $type);
                 break;
             case 'critical_enquiry':
                 $critical_enquiry = CriticalEnquiry::get($user);
                 display_status_messages();
                 echo display_critical_enquiry($critical_enquiry, $type);
                 break;
             case 'community_based_project':
                 $community_based_project = CommunityBasedProject::get($user);
                 display_status_messages();
                 echo display_community_based_project($community_based_project, $type);
                 break;
             case 'research_citations':
                 $research_citations = ResearchCitations::get($user);
                 display_status_messages();
                 echo display_research_citations($research_citations, $type);
                 break;
             case 'observerships':
                 $observerships = Observerships::get($user);
                 display_status_messages();
                 echo display_observerships($observerships, "public");
                 break;
         }
     }
 }
Beispiel #19
0
 function Alert_topic($alert_post, $alert_title, $alert_contents)
 {
     global $LANG;
     try {
         $topic_infos = PersistenceContext::get_querier()->select_single_row(PREFIX . 'forum_topics', array("idcat", "title"), 'WHERE id=:id', array('id' => $alert_post));
     } catch (RowNotFoundException $e) {
         $error_controller = PHPBoostErrors::unexisting_element();
         DispatchManager::redirect($error_controller);
     }
     $result = PersistenceContext::get_querier()->insert(PREFIX . "forum_alerts", array('idcat' => $topic_infos['idcat'], 'idtopic' => $alert_post, 'title' => $alert_title, 'contents' => $alert_contents, 'user_id' => AppContext::get_current_user()->get_id(), 'status' => 0, 'idmodo' => 0, 'timestamp' => time()));
     $alert_id = $result->get_last_inserted_id();
     $contribution = new Contribution();
     //The id of the file in the module. It's useful when the module wants to search a contribution (we will need it in the file edition)
     $contribution->set_id_in_module($alert_id);
     //The entitled of the contribution
     $contribution->set_entitled(sprintf($LANG['contribution_alert_moderators_for_topics'], stripslashes($alert_title)));
     //The URL where a validator can treat the contribution (in the file edition panel)
     $contribution->set_fixing_url('/forum/moderation_forum.php?action=alert&id=' . $alert_id);
     //Description
     $contribution->set_description(stripslashes($alert_contents));
     //Who is the contributor?
     $contribution->set_poster_id(AppContext::get_current_user()->get_id());
     //The module
     $contribution->set_module('forum');
     //It's an alert, we will be able to manage other kinds of contributions in the module if we choose to use a type.
     $contribution->set_type('alert');
     //Assignation des autorisations d'écriture / Writing authorization assignation
     $contribution->set_auth(Authorizations::capture_and_shift_bit_auth(ForumService::get_categories_manager()->get_heritated_authorizations($topic_infos['idcat'], Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT));
     //Sending the contribution to the kernel. It will place it in the contribution panel to be approved
     ContributionService::save_contribution($contribution);
 }
 public function run()
 {
     // $faker = Faker::create();
     // foreach(range(1, 10) as $index)
     // {
     // 	Contribution::create([
     // 	]);
     // }
     $contribution = new Contribution();
     $contribution->user_id = 3;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 4;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 5;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 6;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 1;
     $contribution->pitch_id = 2;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 2;
     $contribution->pitch_id = 2;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 3;
     $contribution->pitch_id = 2;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 4;
     $contribution->pitch_id = 2;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 5;
     $contribution->pitch_id = 2;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 6;
     $contribution->pitch_id = 2;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 1;
     $contribution->pitch_id = 3;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 2;
     $contribution->pitch_id = 3;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 3;
     $contribution->pitch_id = 3;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 4;
     $contribution->pitch_id = 3;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 5;
     $contribution->pitch_id = 3;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 6;
     $contribution->pitch_id = 3;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 1;
     $contribution->pitch_id = 4;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 2;
     $contribution->pitch_id = 4;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 3;
     $contribution->pitch_id = 4;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 4;
     $contribution->pitch_id = 4;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 5;
     $contribution->pitch_id = 4;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 6;
     $contribution->pitch_id = 4;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 1;
     $contribution->pitch_id = 5;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 2;
     $contribution->pitch_id = 5;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 3;
     $contribution->pitch_id = 5;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 4;
     $contribution->pitch_id = 5;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 5;
     $contribution->pitch_id = 5;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 6;
     $contribution->pitch_id = 5;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 1;
     $contribution->pitch_id = 6;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 2;
     $contribution->pitch_id = 6;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 3;
     $contribution->pitch_id = 6;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 4;
     $contribution->pitch_id = 6;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 5;
     $contribution->pitch_id = 6;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 6;
     $contribution->pitch_id = 6;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 7;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 8;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 9;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 10;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 11;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 12;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 16;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 18;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 13;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 7;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 8;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 9;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 10;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 11;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 12;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 16;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 18;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 13;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
     $contribution = new Contribution();
     $contribution->user_id = 14;
     $contribution->pitch_id = 1;
     $contribution->amount = "20";
     $contribution->save();
 }
 /**
  * 
  * @param int $id
  * @return Contribution
  */
 public static function get($id)
 {
     global $db;
     $query = "SELECT * FROM `student_contributions` WHERE `id` = " . $db->qstr($id);
     $result = $db->getRow($query);
     if ($result) {
         $contribution = Contribution::fromArray($result);
         return $contribution;
     }
 }
 public function parsePoi($row)
 {
     $parentCat = new ParentCategory();
     $subCat = new Category();
     $poiUser = new User();
     $poiUser->initWithId($row['supUid'], $row['username'], $row['password'], $row['email'], $row['previlege'], $row['status']);
     $parentCatUser = $this->userController->find($row['supUid']);
     $subCatUser = $this->userController->find($row['subUid']);
     $parentCat->initWithId($row['supId'], $row['supCategory'], $parentCatUser, $row['supDate']);
     $subCat->initWithId($row['subId'], $parentCat, $row['subCategory'], $subCatUser, $row['subDate']);
     $contribution = new Contribution();
     $contribution->setId($row['contributionId']);
     $poi = new POI();
     $poi->initWithId($row['pId'], $row['name'], $row['address'], $row['position'], $subCat, $row['phone'], $row['poiEmail'], $row['website'], $row['poiDate'], $row['update_date'], $contribution, $poiUser);
     return $poi;
 }
 private function contribution_actions(DownloadFile $downloadfile, $id)
 {
     if ($downloadfile->get_id() === null) {
         if ($this->is_contributor_member()) {
             $contribution = new Contribution();
             $contribution->set_id_in_module($id);
             $contribution->set_description(stripslashes($this->form->get_value('contribution_description')));
             $contribution->set_entitled($downloadfile->get_name());
             $contribution->set_fixing_url(DownloadUrlBuilder::edit($id)->relative());
             $contribution->set_poster_id(AppContext::get_current_user()->get_id());
             $contribution->set_module('download');
             $contribution->set_auth(Authorizations::capture_and_shift_bit_auth(DownloadService::get_categories_manager()->get_heritated_authorizations($downloadfile->get_id_category(), Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT));
             ContributionService::save_contribution($contribution);
         }
     } else {
         $corresponding_contributions = ContributionService::find_by_criteria('download', $id);
         if (count($corresponding_contributions) > 0) {
             $downloadfile_contribution = $corresponding_contributions[0];
             $downloadfile_contribution->set_status(Event::EVENT_STATUS_PROCESSED);
             ContributionService::save_contribution($downloadfile_contribution);
         }
     }
     $downloadfile->set_id($id);
 }
 public function process()
 {
     global $ENTRADA_USER;
     $user = $this->_user;
     $translator = $this->_translator;
     $type = $this->type;
     static $valid = array("studentships" => array("add", "remove", "edit"), "clineval" => array("add", "remove", "edit"), "internal_awards" => array("add", "remove", "edit"), "student_run_electives" => array("add", "remove", "edit"), "observerships" => array("add", "remove", "edit"), "int_acts" => array("add", "remove", "edit"), "external_awards" => array("approve", "unapprove", "reject", "add", "edit"), "contributions" => array("approve", "unapprove", "reject", "add", "edit"), "critical_enquiry" => array("approve", "unapprove", "reject", "add", "edit"), "community_based_project" => array("approve", "unapprove", "reject", "add", "edit"), "research_citations" => array("approve", "unapprove", "reject", "add", "edit", "resequence"));
     $section = filter_input(INPUT_GET, 'mspr-section', FILTER_CALLBACK, array('options' => 'strtolower'));
     if ($section) {
         $params = array('entity_id' => FILTER_VALIDATE_INT, 'action' => array('filter' => FILTER_CALLBACK, 'options' => 'strtolower'), 'comment' => FILTER_SANITIZE_STRING, 'user_id' => FILTER_VALIDATE_INT);
         $inputs = filter_input_array(INPUT_POST, $params);
         extract($inputs);
         if (!$action) {
             add_error($translator->translate("mspr_no_action"));
         }
         if (!array_key_exists($section, $valid)) {
             add_error($translator->translate("mspr_invalid_section"));
         } else {
             if (!in_array($action, $valid[$section])) {
                 add_error($translator->translate("mspr_invalid_action"));
             }
         }
         if ($action == "reject" && MSPR_REJECTION_REASON_REQUIRED) {
             if (!$comment) {
                 add_error($translator->translate("mspr_no_reject_reason"));
             }
         }
         if (!has_error() && in_array($action, array("add", "edit", "resequence"))) {
             $inputs = get_mspr_inputs($section);
             process_mspr_inputs($section, $inputs, $translator);
             //modifies inputs/adds errors
         }
         if (!has_error()) {
             $inputs['user_id'] = $user_id;
             if ($action == "add") {
                 if (AUTO_APPROVE_ADMIN_MSPR_SUBMISSIONS) {
                     $inputs['status'] = 1;
                 }
                 switch ($section) {
                     case "clineval":
                         ClinicalPerformanceEvaluation::create($inputs);
                         break;
                     case "observerships":
                         Observership::create($inputs);
                         break;
                     case 'studentships':
                         Studentship::create($inputs);
                         break;
                     case 'internal_awards':
                         InternalAwardReceipt::create($inputs);
                         break;
                     case 'external_awards':
                         ExternalAwardReceipt::create($inputs);
                         break;
                     case 'contributions':
                         Contribution::create($inputs);
                         break;
                     case 'student_run_electives':
                         StudentRunElective::create($inputs);
                         break;
                     case 'int_acts':
                         InternationalActivity::create($inputs);
                         break;
                     case 'critical_enquiry':
                         if (CriticalEnquiry::get($user_id)) {
                             add_error($translator->translate("mspr_too_many_critical_enquiry"));
                         } else {
                             CriticalEnquiry::create($inputs);
                         }
                         break;
                     case 'community_based_project':
                         if (CommunityBasedProject::get($user_id)) {
                             add_error($translator->translate("mspr_too_many_community_based_project"));
                         } else {
                             CommunityBasedProject::create($inputs);
                         }
                         break;
                     case 'research_citations':
                         ResearchCitation::create($inputs);
                         break;
                 }
             } elseif ($action == "resequence") {
                 switch ($section) {
                     case 'research_citations':
                         ResearchCitations::setSequence($user_id, $inputs['research_citations']);
                         break;
                 }
             } else {
                 //everything else requires an entity
                 if ($entity_id) {
                     $entity = get_mspr_entity($section, $entity_id);
                     if ($entity) {
                         switch ($action) {
                             case "approve":
                                 $entity->approve();
                                 break;
                             case "unapprove":
                                 $entity->unapprove();
                                 break;
                             case "remove":
                                 $entity->delete();
                                 break;
                             case "edit":
                                 if ($entity instanceof Approvable) {
                                     if (AUTO_APPROVE_ADMIN_MSPR_EDITS) {
                                         $inputs['comment'] = "";
                                         $inputs['status'] = 1;
                                     } else {
                                         $inputs['comment'] = $entity->getComment();
                                         $inputs['status'] = $entity->getStatus();
                                     }
                                 }
                                 $entity->update($inputs);
                                 //inputs processed above
                                 break;
                             case "reject":
                                 if (MSPR_REJECTION_SEND_EMAIL) {
                                     $sub_info = get_submission_information($entity);
                                     $reason_type = !$comment ? "noreason" : "reason";
                                     $active_user = User::get($ENTRADA_USER->getID());
                                     if ($active_user && $type) {
                                         submission_rejection_notification($reason_type, array("firstname" => $user->getFirstname(), "lastname" => $user->getLastname(), "email" => $user->getEmail()), array("to_fullname" => $user->getFirstname() . " " . $user->getLastname(), "from_firstname" => $active_user->getFirstname(), "from_lastname" => $active_user->getLastname(), "reason" => clean_input($comment, array("notags", "specialchars")), "submission_details" => $sub_info, "application_name" => APPLICATION_NAME . " MSPR System"));
                                     } else {
                                         add_error($translator->translate("mspr_email_failed"));
                                     }
                                 }
                                 $entity->reject($comment);
                                 break;
                         }
                     } else {
                         add_error($translator->translate("mspr_invalid_entity"));
                     }
                 } else {
                     add_error($translator->translate("mspr_no_entity"));
                 }
             }
         }
         switch ($section) {
             case 'studentships':
                 $studentships = Studentships::get($user);
                 display_status_messages();
                 echo display_studentships($studentships, $type);
                 break;
             case 'clineval':
                 $clinical_evaluation_comments = ClinicalPerformanceEvaluations::get($user);
                 display_status_messages();
                 echo display_clineval($clinical_evaluation_comments, $type);
                 break;
             case 'internal_awards':
                 $internal_awards = InternalAwardReceipts::get($user);
                 display_status_messages();
                 echo display_internal_awards($internal_awards, $type);
                 break;
             case 'external_awards':
                 $external_awards = ExternalAwardReceipts::get($user);
                 display_status_messages();
                 echo display_external_awards($external_awards, $type);
                 break;
             case 'contributions':
                 $contributions = Contributions::get($user);
                 display_status_messages();
                 echo display_contributions($contributions, $type);
                 break;
             case 'student_run_electives':
                 $student_run_electives = StudentRunElectives::get($user);
                 display_status_messages();
                 echo display_student_run_electives($student_run_electives, $type);
                 break;
             case 'observerships':
                 $observerships = Observerships::get($user);
                 display_status_messages();
                 echo display_observerships($observerships, $type);
                 break;
             case 'int_acts':
                 $int_acts = InternationalActivities::get($user);
                 display_status_messages();
                 echo display_international_activities($int_acts, $type);
                 break;
             case 'critical_enquiry':
                 $critical_enquiry = CriticalEnquiry::get($user);
                 display_status_messages();
                 echo display_critical_enquiry($critical_enquiry, $type);
                 break;
             case 'community_based_project':
                 $community_based_project = CommunityBasedProject::get($user);
                 display_status_messages();
                 echo display_community_based_project($community_based_project, $type);
                 break;
             case 'research_citations':
                 $research_citations = ResearchCitations::get($user);
                 display_status_messages();
                 echo display_research_citations($research_citations, $type);
                 break;
         }
     }
 }