'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_permission(){
return array(
'access cloud_comments' => array(
'title' => t('access cloud_comments'),
'restrict access' => TRUE,
),
'reply cloud_comments' => array(
'title' => t('reply cloud_comments'),
'restrict access' => TRUE,
),
);
} // function cloud_comments_perm
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
function cloud_comments_help($path, $arg) {
$output = '';
switch($path) {
case "admin/help#cloud_comments":
$output = "
" . 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_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, array(':example_id' => $example_id));
while ($row = $query_result->fetchObject()) {
$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 = :book";
$qr = db_query($q, array(':book'=>$row->books));
$obj = $qr->fetchObject();
$page_content .= t("
Category: ") . $categories[$row->category] . t("
");
$page_content .= t("
Book: ") . $obj->book . t("
");
$q = "SELECT name from {textbook_companion_chapter} where id = :chapter";
$qr = db_query($q, array(':chapter' => $row->chapter));
$obj = $qr->fetchObject();
$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 = :example";
$qr = db_query($q, array(':example' => $row->example));
$obj = $qr->fetchObject();
$example_link = $obj->caption?l($obj->caption,"https://cloud.scilab.in/index?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("
");
$cloud_comments_reply_form = drupal_get_form("cloud_comments_reply_form_".$row->id, $row->id);
$page_content .= drupal_render($cloud_comments_reply_form);
$page_content .= t("
");
$page_content .= t("
x");
}
}
$page_content .= t("
");
} // while ends
$page_content .= theme('pager', array('header' => NULL, 'rows' => 5 ));
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, $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',
'#default_value' => $comment_id
);
$form["submit"] = array(
'#type' => 'submit',
'#value' => 'Reply'
);
return $form;
} // function reply_form
function cloud_comments_reply_form_submit($form, &$form_state) {
global $user;
$query = "UPDATE {scilab_cloud_comment} SET reply = :reply, user= :users, reply_status = 1 WHERE id = :id";
$query_result = db_query($query, array(':reply'=> $form_state["values"]["content"], ':users' => $user->name, ':id' => $form_state["values"]["hidden"]));
$email_query = "SELECT email FROM {scilab_cloud_comment} WHERE id = :id";
$result = db_query($email_query, array(':id' => $form_state["values"]["hidden"]));
$obj = $result->fetchObject();
/* $message = array(
'to' => $obj->email,
'subject' => t("Comment Reply"),
'body' => array(0=> t($form_state["values"]["content"])),
'headers' => array("From" => "textbook@scilab.in", "Content-type" => "text/html; charset=iso-8859-1")
);
send_mail($message);
*/
/* sending mail */
$to = $obj->email;
$subject = t("Scilab on Cloud Comment Reply");
$message = t($form_state["values"]["content"]);
// drupal_mail_send($message);
send_mail("textbook@scilab.in", $to, $subject, $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 = :id";
$query_result = db_query($query, array(':id' => $comment_id));
if ($query_result->rowCount() > 0) {
drupal_set_message("Deleted");
} else {
drupal_set_message("MySQL Error: row deletion failed.");
}
}
drupal_goto("cloud_comments");
}
?>
Comment:
") . $row->comment . t("