diff options
author | Jayaram R Pai | 2014-07-01 15:38:33 +0530 |
---|---|---|
committer | Jayaram R Pai | 2014-07-01 15:38:33 +0530 |
commit | 5b038d3a7a70c69f31f669cd11ed0ec50c9fbbe8 (patch) | |
tree | d2fa9288ee15c7389cfbb1089c40e52756cef83c | |
download | fellowship_testimonials-5b038d3a7a70c69f31f669cd11ed0ec50c9fbbe8.tar.gz fellowship_testimonials-5b038d3a7a70c69f31f669cd11ed0ec50c9fbbe8.tar.bz2 fellowship_testimonials-5b038d3a7a70c69f31f669cd11ed0ec50c9fbbe8.zip |
initial commit
-rwxr-xr-x | .gitignore | 41 | ||||
-rw-r--r-- | testimonials.info | 3 | ||||
-rw-r--r-- | testimonials.module | 173 |
3 files changed, 217 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..b6788e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# Ignore configuration files that may contain sensitive information. +sites/*/*settings*.php + +# Ignore paths that contain generated content. +cache/ +files/ +sites/*/files +sites/*/private + +# Ignore default text files +robots.txt +/CHANGELOG.txt +/COPYRIGHT.txt +/INSTALL*.txt +/LICENSE.txt +/MAINTAINERS.txt +/UPGRADE.txt +/README.txt +sites/all/README.txt +sites/all/modules/README.txt +sites/all/themes/README.txt + +# Ignore everything but the "sites" folder ( for non core developer ) +.htaccess +web.config +authorize.php +cron.php +index.php +install.php +update.php +xmlrpc.php +/includes +/misc +/modules +/profiles +/scripts +/themes + +# Ignore vim temp. files +*.swo +*.swp diff --git a/testimonials.info b/testimonials.info new file mode 100644 index 0000000..083f62d --- /dev/null +++ b/testimonials.info @@ -0,0 +1,3 @@ +name = Testimonials +description = To manage and display testimonials +core = 6.x diff --git a/testimonials.module b/testimonials.module new file mode 100644 index 0000000..e63820c --- /dev/null +++ b/testimonials.module @@ -0,0 +1,173 @@ +<?php + function testimonials_menu() { + $items = array(); + $items["testimonials"] = array( + "title" => "Testimonials", + "page callback" => "testimonials_display_all", + "access arguments" => array("view testimonials"), + "type" => MENU_CALLBACK + ); + $items["testimonials/add"] = array( + "title" => "Add Testimonials", + "page callback" => "testimonials_add_all", + "access arguments" => array("manage testimonials"), + "type" => MENU_CALLBACK + ); + $items["testimonials/edit"] = array( + "title" => "Edit Testimonials", + "page callback" => "testimonials_edit_all", + "access arguments" => array("manage testimonials"), + "type" => MENU_CALLBACK + ); + $items["testimonials/delete"] = array( + "title" => "Delete Testimonial", + "page callback" => "testimonials_delete_all", + "access arguments" => array("manage testimonials"), + "type" => MENU_CALLBACK + ); + return $items; + } + + function testimonials_perm() { + return array( + "view testimonials", + "manage testimonials", + ); + } + + function testimonials_add_form($form_state, $testimonial_id=0) { + $query = " + SELECT * FROM testimonials + WHERE id = {$testimonial_id} + "; + $result = db_query($query); + $row = db_fetch_object($result); + + $form = array(); + $form["name"] = array( + "#type" => "textfield", + "#title" => "Name", + "#default_value" => $row->name, + "#required" => TRUE + ); + $form["department"] = array( + "#type" => "textfield", + "#title" => "Department", + "#default_value" => $row->department, + "#required" => TRUE + ); + $form["university"] = array( + "#type" => "textfield", + "#title" => "University", + "#default_value" => $row->university, + "#required" => TRUE + ); + $form["contribution"] = array( + "#type" => "textfield", + "#title" => "Contribution", + "#default_value" => $row->contribution, + "#required" => TRUE + ); + $form["reference"] = array( + "#type" => "textfield", + "#title" => "Reference", + "#default_value" => $row->reference, + "#required" => TRUE + ); + $form["body"] = array( + "#type" => "textarea", + "#title" => "Testimonial", + "#default_value" => $row->body, + "#required" => TRUE + ); + $form["testimonial_id"] = array( + "#type" => "hidden", + "#value" => $testimonial_id + ); + $form["submit"] = array( + "#type" => "submit", + "#value" => "Submit" + ); + return $form; + } + + function testimonials_add_form_validate($form, &$form_state) { + // for future use + } + + function testimonials_add_form_submit($form, &$form_state) { + $v = $form_state["values"]; + if($v["testimonial_id"]) { + $query = " + UPDATE testimonials SET + name = '%s', department = '%s', university = '%s', + contribution = '%s', reference = '%s', body = '%s' + WHERE id = %d + "; + $result = db_query($query, + $v["name"], $v["department"], $v["university"], + $v["contribution"], $v["reference"], $v["body"], + $v["testimonial_id"] + ); + } else { + $query = " + INSERT INTO testimonials + (name, department, university, contribution, reference, body) + VALUES + ('%s', '%s', '%s', '%s', '%s', '%s') + "; + $result = db_query($query, + $v["name"], $v["department"], $v["university"], + $v["contribution"], $v["reference"], $v["body"] + ); + } + if(!$result) { + drupal_set_message("Something went wrong, please try again.", "error"); + } else { + drupal_set_message("Testimonial added successfully", "status"); + } + } + + function testimonials_add_all() { + $page_content = ""; + $page_content .= drupal_get_form("testimonials_add_form"); + return $page_content; + } + + function testimonials_edit_all($testimonial_id=0) { + $page_content = ""; + if($testimonial_id){ + $page_content .= drupal_get_form("testimonials_add_form", $testimonial_id); + } else { + $query = " + SELECT * FROM testimonials + ORDER BY time DESC + "; + $result = db_query($query); + $headers = array( + "Name", "University", "Action" + ); + $rows = array(); + while($row = db_fetch_object($result)) { + $item = array( + $row->name, + $row->university, + l("Edit", "testimonials/edit/{$row->id}") ." | ". + l("Delete", "testimonials/delete/{$row->id}") + ); + array_push($rows, $item); + } + $page_content .= theme("table", $headers, $rows); + } + return $page_content; + } + + function testimonials_display_all() { + $page_content = ""; + return $page_content; + } + + function testimonials_init() { + // for future use + } +?> |