Simple status box for the sidebar.
[elgg_plugins.git] / ratings / rating_action.php
blobbc6b277490daff29b064cc253308325fd0c666ea
1 <?php
3 /** @file rating_action.php Handle ratings action.
4 * This file handles a rating action based on input
5 */
7 @require_once("../../includes.php");
9 global $messages, $CFG;
11 // Get parameters
12 $action = optional_param('action',''); // Action - rate etc
13 $rating_ident = optional_param('rating_ident',''); // Ident of the action field
14 $ratedby = optional_param('ratedby',''); // User rating this object
15 $rating = optional_param('rating',''); // Rating they gave it
16 $displaymode = optional_param('displaymode',''); // Display XML or normal (default)
17 $returnurl = urldecode(optional_param('returnurl','')); // The return url
18 $object_id = optional_param('object_id','');
19 $object_type = optional_param('object_type','');
20 $userid = $ratedby;
22 $page = "";
24 if ($action) {
26 if ($action == "rating::add")
28 // Store the rating
29 $success = ratings_storerating($rating_ident, $ratedby, $rating);
31 // Message
32 if ($success)
34 $messages[] = __gettext("Object rated.");
35 if ($displaymode=="xml")
36 $messages[] = __gettext(" Click here to see the updated rating.");
38 // Hook for the river plugin (if installed)
39 if (function_exists('river_save_event'))
41 $username = "<a href=\"" . river_get_userurl($userid) . "\">" . user_info("username", $userid) . "</a>";
43 river_save_event($userid, $object_id, $userid, $object_type, $username . " " . __gettext("rated") . " " . river_get_friendly_id($object_type, $object_id) );
47 else
49 $messages[] = __gettext("Object could not be rated");
52 // Are we outputing XML or text
53 if ($displaymode=="xml")
55 $message = implode(" \n", $messages);
56 if ($success)
57 $err = "0";
58 else
59 $err = "1";
61 $page = "<ajax>\n<message>$message</message>\n<error>$err</error>\n</ajax>\n";
63 else
65 $page = <<< END
66 <p>Your rating has been recorded.</p>
67 <a href="$returnurl">Go back...</a>
68 END;
70 templates_page_setup();
72 $page = templates_page_draw(
73 array( sitename,
74 templates_draw(
75 array(
76 'body' => $page,
77 'title' => __gettext("Rating"),
78 'context' => 'contentholder'
88 // Output the page
89 if ($displaymode=="xml")
90 header("Content-type: text/xml");
91 echo $page;