" . t("Displays the Comments on cloud and enables the admin to reply to them via e-mail: textbook@scilab.in") . "
";
break;
}
return $output;
} // function cloud_comments_help
function cloud_comments_perm() {
return array("access cloud_comments", "reply cloud_comments");
} // function cloud_comments_perm
function cloud_comments_all($example_id=0) {
$types = array(
"None",
"Blank Code / Incorrect code",
"Output error",
"Execution error",
"Missing example(s)",
"None",
"Blank output",
"Any other"
);
$categories = array(
"Others",
"Fluid Mechanics",
"Control Theory & Control Systems",
"Chemical Engineering",
"Thermodynamics",
"Mechanical Engineering",
"Signal Processing",
"Digital Communications",
"Electrical Technology",
"Mathematics & Pure Science",
"Analog Electronics",
"Digital Electronics",
"Computer Programming",
"Others"
);
$page_content = "";
if($example_id) {
$query = "SELECT scc.*, tcc.number AS chapter_no, tce.number AS example_no FROM scilab_cloud_comment scc LEFT JOIN textbook_companion_chapter tcc ON tcc.id = scc.chapter LEFT JOIN textbook_companion_example tce ON tce.id = scc.example WHERE scc.example = {$example_id} ORDER BY scc.date DESC";
} else {
$query = "SELECT scc.*, tcc.number AS chapter_no, tce.number AS example_no FROM scilab_cloud_comment scc LEFT JOIN textbook_companion_chapter tcc ON tcc.id = scc.chapter LEFT JOIN textbook_companion_example tce ON tce.id = scc.example ORDER BY scc.date DESC";
}
$query_result = pager_query($query, 5, 0 );
//$query_result = db_query($query);
while ($row = db_fetch_object($query_result)) {
$border = $row->reply_status?"sent":"not-sent";
$page_content .= t("");
$page_content .= t("
") . $row->date . t("
");
if (user_access("reply cloud_comments")) {
$page_content .= t("
From: ") . $row->email . t("
");
}
$page_content .= t("
Type: ") . $types[$row->type] . t("
");
$q = "SELECT book from {textbook_companion_preference} where id = '%d'";
$qr = db_query($q, $row->books);
$obj = db_fetch_object($qr);
$page_content .= t("
Category: ") . $categories[$row->category] . t("
");
$page_content .= t("
Book: ") . $obj->book . t("
");
$q = "SELECT name from {textbook_companion_chapter} where id = '%d'";
$qr = db_query($q, $row->chapter);
$obj = db_fetch_object($qr);
$chapter = $obj->name?$obj->name:"None";
$page_content .= t("
Chapter: ") . $chapter . ($row->chapter_no?" ({$row->chapter_no})":"") . t("
");
$q = "SELECT caption from {textbook_companion_example} where id = '%d'";
$qr = db_query($q, $row->example);
$obj = db_fetch_object($qr);
$example_link = $obj->caption?l($obj->caption,"http://cloud.scilab.in/index.php?eid=".$row->example):"None";
$page_content .= t("
Example: ") . $example_link . ($row->example_no?" ({$row->example_no})":"") . t("
");
$page_content .= t("");
if ($row->reply) {
if(!$row->user){
$page_content .= t("
Reply Sent:
") . $row->reply . t("
");
}else{
$page_content .= t("
Reply Sent By ".$row->user.":
") . $row->reply . t("
");
}
}
else {
if (user_access("reply cloud_comments")) {
$page_content .= t("
Reply");
$page_content .= t("
");
$page_content .= drupal_get_form("cloud_comments_reply_form_".$row->id, $row->id);
$page_content .= t("
");
$page_content .= t("
x");
}
}
$page_content .= t("
");
} // while ends
$page_content .= theme('pager', NULL, 5, 0);
return $page_content;
} // function cloud_comments_all
function cloud_comments_forms($form_id) {
$forms = array();
if (strpos($form_id, 'cloud_comments_reply_form_') === 0) {
$forms[$form_id] = array(
'callback' => 'cloud_comments_reply_form',
);
}
return $forms;
} // function cloud_comments_forms
function cloud_comments_reply_form($form_state, $comment_id) {
$form = array();
$form["#submit"] = array(
'cloud_comments_reply_form_submit',
);
$form["content"] = array(
'#type' => 'textarea',
'#wysiwyg' => True
);
$form["hidden"] = array(
'#type' => 'hidden',
'#value' => $comment_id
);
$form["submit"] = array(
'#type' => 'submit',
'#value' => 'submit'
);
return $form;
} // function reply_form
function cloud_comments_reply_form_submit($form, &$form_state) {
global $user;
$query = "UPDATE {scilab_cloud_comment} SET reply = '%s', user= '%s', reply_status = 1 WHERE id = %d";
$query_result = db_query($query, $form_state["values"]["content"], $user->name, $form_state["values"]["hidden"]);
$email_query = "SELECT email FROM {scilab_cloud_comment} WHERE id = %d";
$result = db_query($email_query, $form_state["values"]["hidden"]);
$obj = db_fetch_object($result);
$message = array(
'to' => $obj->email,
'subject' => t("Comment Reply"),
'body' => t($form_state["values"]["content"]),
'headers' => array("From" => "textbook@scilab.in", "Content-type" => "text/html; charset=iso-8859-1")
);
drupal_mail_send($message);
if (!$query_result) {
drupal_set_message("Database updation failed");
} else {
drupal_set_message("Message sent. . .");
}
} // function reply_form_submit
function cloud_comments_delete($comment_id=NULL) {
if ($comment_id && user_access("reply cloud_comments")) {
$query = "DELETE FROM {scilab_cloud_comment} WHERE id = %d";
$query_result = db_query($query, $comment_id);
if (db_affected_rows() > 0) {
drupal_set_message("Deleted");
} else {
drupal_set_message("MySQL Error: row deletion failed.");
}
}
drupal_goto("cloud_comments");
}
function cloud_comments_menu() {
$items = array();
$items['cloud_comments'] = array(
'title' => 'Cloud Comments',
'page callback' => 'cloud_comments_all',
'access arguments' => array("access cloud_comments"),
'type' => MENU_CALLBACK,
);
$items['cloud_comments/delete'] = array(
'title' => 'Cloud Comments',
'page callback' => 'cloud_comments_delete',
'access arguments' => array("access cloud_comments"),
'type' => MENU_CALLBACK,
);
return $items;
} // function cloud_comments_menu
function cloud_comments_init() {
drupal_add_css(drupal_get_path("module", "cloud_comments") . "/css/cloud_comments.css");
drupal_add_js(drupal_get_path("module", "cloud_comments") . "/js/cloud_comments.js");
} //function cloud_comments_init
?>
Comment:
") . $row->comment . t("