Tuesday 10 March 2015

Leave Application

<?php



function custom_menu() {
  $items = array();


$items['examples/form-example'] = array( //this creates a URL that will call this form at "examples/form-example"
    'title' => 'Leave Application', //page title
    'description' => 'A form to mess around with.',
    'page callback' => 'drupal_get_form', //this is the function that will be called when the page is accessed.  for a form, use drupal_get_form
    'page arguments' => array('custom_example_form'), //put the name of the form here
    'access callback' => TRUE
  );
 $items['examples/leaveslist'] = array( //this creates a URL that will call this form at "examples/form-example"
    'title' => 'Leave List', //page title
    'description' => 'A form to mess around with.',
    'page callback' => 'custom_leaves_list', //this is the function that will be called when the page is accessed.  for a form, use drupal_get_form
    'access callback' => TRUE
  );

  return $items;
}

function custom_example_form($form, &$form_state) {
 global $user;
 $form['usernames'] = array(
    '#type' => 'textfield',
    '#value' => $user->name,
    '#attributes' => array('autocomplete' =>'off','readonly' => 'readonly'),
 
);
$form['start_date'] = array(
  '#type' => 'date_popup',
  '#title' => t("Leave Start Date"),
  '#required' => TRUE,
  '#date_format' => 'd-m-Y',
  '#attributes' => array('autocomplete' =>'off','readonly' => 'readonly'),
 
 );
 $form['end_date'] = array(
  '#type' => 'date_popup',
  '#title' => t("Leave end Date"),
  '#required' => TRUE,
  '#date_format' => 'd-m-Y',
  '#attributes' => array('autocomplete' =>'off','readonly' => 'readonly'),
 
 );
 $form['number_of_days'] = array(
    '#title' => 'Number of Days?',
    '#type' => 'textfield',
);
 $form['reason'] = array(
    '#type' => 'textarea',
    '#title' => 'Reason For Leave?',
    '#required' => TRUE,
 );
$form['submit_button'] = array(
    '#type' => 'submit',
    '#value' => t('Click Here!'),
 
  );

  return $form;
}


function custom_example_form_submit($form, &$form_state)
{
$user_name = $form_state['values']['usernames'];
$start_date = $form_state['values']['start_date'];
$end_date = $form_state['values']['end_date'];
$number_of_days = $form_state['values']['number_of_days'];
$reason_for_leave = $form_state['values']['reason'];

$nid = db_insert('leaves_list')
->fields(array(
  'uid' => $user_name,
  'leaves_remaining' => '2',
  'leave_start' => $start_date,
  'leave_enddate' => $end_date,
  'number_leaves' => $number_of_days,
))
->execute();



  drupal_set_message(t('The form has been submitted.'));
}

function custom_leaves_list()
{



$result = db_select('leaves_list', 'c')
    ->fields('c')
    ->execute()
    ->fetchAll();

echo '<table width="100%">';
echo '<tr class="heading"><th>Name</th><th>Number of leaves</th><th>Leaves Remaining</th><th>Start Date</th><th>End Date</th></tr>';
foreach($result as $res)
{
echo "<tr>";
echo '<td align="center">'.$res->uid."</td>";
echo '<td align="center">'.$res->number_leaves."</td>";
echo '<td align="center">'.$res->leaves_remaining."</td>";
$star_date = date("d-m-Y", strtotime($res->leave_start));
echo '<td align="center">'.$star_date."</td>";
$en_date = date("d-m-Y", strtotime($res->leave_enddate));
echo '<td align="center">'.$en_date."</td>";
echo "</tr>";
}
echo "</table>";





}



?>


DRUPAL Means...

D - Developers
R - Respect
U - Unrivalled
P - Positivity
A - All-inclusive
L - Long days, long nights

Drupal Database Schema Design


Drupal Performance

http://drupal.stackexchange.com/questions/24180/how-do-you-improve-drupal-performance


Performance and scalability Testing Module  :
------------------------------------------
https://www.drupal.org/project/blazemeter


maintain Coding Standards of the project : 
----------------------------------------
https://www.drupal.org/project/coder


Best practices for creating and maintaining projects :
----------------------------------------------------
https://www.drupal.org/node/7765

Tips for a great project page