summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscilab_fixer.module177
1 files changed, 177 insertions, 0 deletions
diff --git a/scilab_fixer.module b/scilab_fixer.module
index fb1a831..8955255 100755
--- a/scilab_fixer.module
+++ b/scilab_fixer.module
@@ -7,6 +7,28 @@
"access arguments" => array("fix scilab"),
"type" => MENU_NORMAL_ITEM
);
+ $items["fix/aicte"] = array(
+ "title" => "Add AICTE books",
+ "page callback" => "scilab_fixer_aicte_all",
+ "access arguments" => array("fix scilab"),
+ "access arguments" => array("fix scilab"),
+ "weight" => 30,
+ "type" => MENU_NORMAL_ITEM
+ );
+ $items["fix/aicte/new"] = array(
+ "title" => "Add AICTE books",
+ "page callback" => "scilab_fixer_aicte_all",
+ "access arguments" => array("fix scilab"),
+ "weight" => 1,
+ "type" => MENU_DEFAULT_LOCAL_TASK
+ );
+ $items["fix/aicte/edit"] = array(
+ "title" => "Edit AICTE books",
+ "page callback" => "scilab_fixer_aicte_edit_all",
+ "access arguments" => array("fix scilab"),
+ "weight" => 2,
+ "type" => MENU_LOCAL_TASK
+ );
$items["fix/ajax"] = array(
"page callback" => "scilab_fixer_ajax",
"access callback" => TRUE,
@@ -160,6 +182,161 @@
exit();
}
+ function scilab_fixer_aicte_form($form_state, $aicte_id) {
+ $query = "
+ SELECT * FROM textbook_companion_aicte
+ WHERE id = {$aicte_id}
+ ";
+ $result = db_query($query);
+ $row = db_fetch_object($result);
+
+ $form = array();
+ $form["book"] = array(
+ "#type" => "textfield",
+ "#title" => "Book Name",
+ "#default_value" => $row->book,
+ "#required" => TRUE
+ );
+ $form["author"] = array(
+ "#type" => "textfield",
+ "#title" => "Author",
+ "#default_value" => $row->author,
+ "#required" => TRUE
+ );
+ $form["category"] = array(
+ "#type" => "select",
+ "#title" => "Book Category",
+ '#options' => array(
+ 0 => 'Please select a category',
+ 1 => 'Fluid Mechanics',
+ 2 => 'Control Theory & Control Systems',
+ 3 => 'Chemical Engineering',
+ 4 => 'Thermodynamics',
+ 5 => 'Mechanical Engineering',
+ 6 => 'Signal Processing',
+ 7 => 'Digital Communications',
+ 8 => 'Electrical Technology',
+ 9 => 'Mathematics & Pure Science',
+ 10 => 'Analog Electronics',
+ 11 => 'Digital Electronics',
+ 12 => 'Computer Programming',
+ 13 => 'Others'
+ ),
+ "#default_value" => $row->category,
+ "#required" => TRUE
+ );
+ $form["isbn"] = array(
+ "#type" => "textfield",
+ "#title" => "ISBN",
+ "#default_value" => $row->isbn,
+ "#required" => FALSE
+ );
+ $form["publisher"] = array(
+ "#type" => "textfield",
+ "#title" => "Publisher",
+ "#default_value" => $row->publisher,
+ "#required" => TRUE
+ );
+ $form["edition"] = array(
+ "#type" => "textfield",
+ "#title" => "Edition",
+ "#default_value" => $row->edition,
+ "#required" => TRUE
+ );
+ $form["year"] = array(
+ "#type" => "textfield",
+ "#title" => "Year of publication",
+ "#default_value" => $row->year,
+ "#required" => TRUE
+ );
+ $form["aicte_id"] = array(
+ "#type" => "hidden",
+ "#value" => $row->id
+ );
+ $form["submit"] = array(
+ "#type" => "submit",
+ "#value" => "Submit"
+ );
+ return $form;
+ }
+
+ function scilab_fixer_aicte_form_validate($form, &$form_state) {
+ if(!$form_state["values"]["category"]) {
+ form_set_error("category", "Please select a category.");
+ }
+ if(!is_numeric($form_state["values"]["edition"])) {
+ form_set_error("edition", "Only digits are allowed.");
+ }
+ if(!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) {
+ form_set_error("year", "Please enter a valid year. eg: 2011.");
+ }
+ }
+
+ function scilab_fixer_aicte_form_submit($form, &$form_state) {
+ $v = $form_state["values"];
+ if($v["aicte_id"]) {
+ $query = "
+ UPDATE textbook_companion_aicte
+ SET book = '%s', author = '%s', category = %d,
+ isbn = '%s', publisher = '%s', edition = %d,
+ year = %d
+ WHERE id = %d
+ ";
+ $result = db_query($query,
+ $v["book"], $v["author"], $v["category"], $v["isbn"],
+ $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"]
+ );
+ drupal_set_message("Book updated successfully", "status");
+ } else {
+ $query = "
+ INSERT INTO textbook_companion_aicte
+ (book, author, category, isbn, publisher, edition, year)
+ VALUES
+ ('%s', '%s', %d, '%s', '%s', %d, %d)
+ ";
+ $result = db_query($query,
+ $v["book"], $v["author"], $v["category"], $v["isbn"],
+ $v["publisher"], $v["edition"], $v["year"]
+ );
+ drupal_set_message("Book added successfully", "status");
+ }
+ }
+
+ function scilab_fixer_aicte_all() {
+ $page_content = "";
+ $page_content .= drupal_get_form("scilab_fixer_aicte_form");
+ return $page_content;
+ }
+
+ function scilab_fixer_aicte_edit_all($aicte_id=0) {
+ $page_content = "";
+ if($aicte_id) {
+ $page_content .= drupal_get_form("scilab_fixer_aicte_form", $aicte_id);
+ } else {
+ $query = "
+ SELECT * FROM textbook_companion_aicte
+ ORDER BY time DESC
+ ";
+ $result = db_query($query);
+ $headers = array(
+ "Book", "Author",
+ "Edition", "Action",
+ );
+ $rows = array();
+ while($row = db_fetch_object($result)) {
+ $item = array(
+ "{$row->book}",
+ "{$row->author}",
+ "{$row->edition}",
+ l(t("Edit"), "fix/aicte/edit/{$row->id}")
+ );
+ array_push($rows, $item);
+ }
+ $page_content .= theme("table", $headers, $rows);
+ }
+ return $page_content;
+ }
+
function scilab_fixer_init() {
drupal_add_css(drupal_get_path("module", "scilab_fixer") . "/css/scilab_fixer.css");
drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/scilab_fixer.js");