How to call different function inside a module in drupal 6 - function

in drupal 6. i have this hook_menu().
$items['graph'] = array(
'title' => t('Sample Graphs'),
'page callback' => 'graph_content',
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
$items['graph/line_graph'] = array(
'title' => t('Line Graph'),
'page callback' => 'line_graph_content',
'type' => MENU_CALLBACK ,
'access arguments' => array('access_content'),
);
i want to go to another page for the line graph. When i go to '?q=graph' it calls the graph_content function. it is working but when I go to '?q=graph/line_graph', the same function call it. the output of 'graph' and 'line_graph' are the same. They are in the same module Who can help me with this issue? THANKS!!

I tested your code in a custom module and it working for me. I have two differents outputs. Test it and let me know if it working for you.
function mymodule_menu() {
$items['graph'] = array(
'title' => t('Sample Graphs'),
'page callback' => 'graph_content',
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
$items['graph/line_graph'] = array(
'title' => t('Line Graph'),
'page callback' => 'line_graph_content',
'type' => MENU_CALLBACK,
'access arguments' => array('access_content'),
);
return $items;
}
function graph_content(){
return 'hello '. __FUNCTION__;
}
function line_graph_content(){
return 'hello '. __FUNCTION__;
}

Related

Drupal 7 function db_insert() causes internal server error (500)

I am building an onsite payment method and among other things I need to save data to a custom db table, after recieving a callback from an external API service.
This is the function:
// callback from external service acting as client
function _api_callback() {
global $user;
$data = json_decode(file_get_contents("php://input"), $assoc = true);
$date = $date['year'] . '-' . $date['month'] . '-' . $date['day'];
$timestamp = strtotime($date);
db_insert('postback')
->fields(array(
'user_id' => $user->uid,
'data' => $data,
'created_date' => $timestamp,
))
->execute(); // save data from external service
}
In the site's access log I can see that my site responds with a 500 code when the external callback arrives.
However if I comment out everything in that function the external callback recieves a 200 response code.
So there is some thing going wrong, when this callback is recieved. It's hard to debug since the callback from the external API service starts a whole new session.
The custom table "postback" was successfully created in the .install file of my custom module and I have checked in phpMyAdmin that the table is present and well. This is the schema() function in the .install file:
function module_payments_schema() {
$schema['postback'] = array(
'description' => 'Data saved from API postback URL.',
'fields' => array(
'id' => array(
'description' => 'Auto incremental id.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE),
'user_id' => array(
'description' => 'User id for the order.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE),
'order_id' => array(
'description' => 'Current order number.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0),
'data' => array(
'description' => 'Postback data from external API.',
'type' => 'varchar',
'length' => 1020,
'not null' => TRUE,
'default' => ''),
'created_date' => array(
'description' => 'Created date and time (yyyy-mm-dd H:i:s).',
'type' => 'varchar',
'mysql_type' => 'DATETIME',
'not null' => TRUE,
),
),
'primary key' => array('id'),
);
return $schema;
}
Anyone who can see what's wrong?
It turns out I needed to format the date value like this...
date('Y-m-d H:i:s');
... in order to work with the mysql DATETIME type.
So the working function now looks like this:
function _api_callback() {
global $user;
$data = json_decode(file_get_contents("php://input"), $assoc = true);
db_insert('postback')
->fields(array(
'user_id' => $user->uid,
'data' => $data,
'created_date' => date('Y-m-d H:i:s');
))
->execute(); // save data from external service
}

Cakephp: group not working

Here is the Model that I've written:
public function getMockTestResultDetails($studentID){
$mockTestResults = array();
$mockTestResults = $this->find('all',array(
'joins' => array(
array(
'table' => 'exam',
'alias' => 'exm',
'type' => 'LEFT',
'conditions' => array('StudentExam.TEMPLATEEXAM=exm.ID' ),
)
),
'fields' => array('exm.ENTRANCEEXAM', 'exm.NAME','count(StudentExam.TEMPLATEEXAM)' ,'StudentExam.IMPROVEMENT_INDEX' ,`StudentExam.EXAM_COMPLETED_ON`,'StudentExam.PHASE_ONE',
'StudentExam.PHASE_TWO','StudentExam.PHASE_THREE','StudentExam.PHASE_FOUR','StudentExam.PHASE_INTERN'),
//'group' => array(`StudentExam.TEMPLATEEXAM`),
'conditions' => array('exm.EXAM_TYPE' => 'MOCK','StudentExam.STUDENT' => $studentID,'StudentExam.STATUS' => 'COMPLETED'),
));
return $mockTestResults;
}
When I comment the line where 'group' is it works and I get a output but it is partial/incomplete output. I must use group to obtain the right answer. The same query when executed on phpmyadmin it works fine but it is not working in cakephp. Am I missing something here or what please suggest me the solution.

Open in a new window in yii2 [For a button dropdown]

how can one open a link in a new tab. in my case i wanna do it in the following code
if( Yii::$app->session->get('department_id') == 5 )
{
$items[] = ['label' => 'Offer Letter',
'url' => Yii::$app->urlManager->createUrl(['dashboard/print_offer_letter', 'id' => $data->id]),
];
i tried like this but didn't work
$items[] = ['label' => 'Offer Letter', ['title'=>'go','target'=>'_blank'],
'url' => Yii::$app->urlManager->createUrl(['dashboard/print_offer_letter', 'id' => $data->id]),
];
any help would be appreciated.
I think you can use something like below:
$items[] = [
'label' => 'items',
'url' => Yii::$app->urlManager->createUrl(['dashboard/print_offer_letter', 'id' => $data->id]),
'linkOptions' => ['target'=>'_blank']
];

Drupal custom form get and record current user

I looked up on the internet and write an custom module.
I want to add a form for people to add some information into database.
I use "data" module to create a table called "profile".
And my module's code is (addfood.module):
<?php
/**
* Implements hook_menu().
*/
function addfood_menu() {
$items['food/add'] = array(
'title' => '新增食物檔案',
'page callback' => 'addfood_page',
'access callback' => TRUE,
);
return $items;
}
/**
* Implements hook_permission.
*/
function addfood_permission() {
return array(
'addfood module' => array(
'title' => t('Addfood module permission'),
));
}
/**
* Returns form render array.
*/
function addfood_form($form, &$form_state) {
if (user_access('addfood module')) {
//Allowed
$form['name'] = array(
'#title' => t('名稱'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['calorie'] = array(
'#title' => t('卡路里'),
'#type' => 'textfield',
'#required' => TRUE,
'#description' => t('填寫卡路里(單位:千卡)'),
);
$form['water'] = array(
'#title' => t('水'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['protein'] = array(
'#title' => t('蛋白質'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['saturated_fat'] = array(
'#title' => t('飽和脂肪'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['trans_fat'] = array(
'#title' => t('反式脂肪'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['carbohydrates'] = array(
'#title' => t('碳水化合物'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['dietary_fiber'] = array(
'#title' => t('膳食纖維'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['cholesterol'] = array(
'#title' => t('膽固醇'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['sodium'] = array(
'#title' => t('鈉'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['sugars'] = array(
'#title' => t('糖'),
'#type' => 'textfield',
'#required' => TRUE,
);
$form['notes'] = array(
'#title' => t('Please explain your what makes you a prime candidate for our beta test'),
'#type' => 'textarea',
'#resizable' => TRUE,
'#description' => t('Beta spaces are limited, but let us know if there is a really good reason to let you in.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
} else {
//Access denied
header('Location: ../user/login?destination=food/add');
}
}
/**
* Menu callback.
*/
function addfood_page() {
return drupal_get_form('addfood_form');
}
/**
* Submission handler for form_example -> Insert into database
*/
function addfood_form_submit($form, &$form_state) {
$fe_id = db_insert('profile')
->fields(array(
'name' => $form_state['values']['name'],
'calorie' => $form_state['values']['calorie'],
'water' => $form_state['values']['water'],
'protein' => $form_state['values']['protein'],
'saturated_fat' => $form_state['values']['saturated_fat'],
'trans_fat' => $form_state['values']['trans_fat'],
'carbohydrates' => $form_state['values']['carbohydrates'],
'dietary_fiber' => $form_state['values']['dietary_fiber'],
'cholesterol' => $form_state['values']['cholesterol'],
'sodium' => $form_state['values']['sodium'],
'notes' => $form_state['values']['notes'],
))
->execute();
drupal_set_message(t('HO GYA Submit!!!!'));
return $form;
}
?>
If I want to record who add the information automatically(by get the current username).
Anyone has idea how to do it? Thank you.
Figure is my table schema.
(source: libk.info)
You can use global user variable to get current user. You can test it:
<?php
global $user;
print_r($user->name);
?>

Drupal Html array. How to reference a changing radio selection within a fieldset

I cannot make this Drupal html array fire the visible property on change of radio option. I have moved everything inside of the fieldset, not sure if this makes any difference.
Does anyone know why it isn't firing?
function services_formation_founders($form, &$form_state) {
$form = array();
$form['#tree'] = TRUE;
$form['description'] = array(
'#type' => 'item',
'#title' => t('Founders form'),
);
$form['founder']['add_officer'] = array(
'#type' => 'fieldset',
'#title' => t('Add Founder'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#states' => array(
'visible' => array(TRUE,
),
),
);
$form['founder']['add_officer']['founder_type'] = array(
'#type' => 'radios',
'#options' => array(
'individual' => t('Individual'),
'corporate' => t('Corporation'),
),
'#default_value'=>'individual',
'#title' => t('What type of Founder?')
);
if (empty($form_state['num_names'])) {
$form_state['num_names'] = 1;
}
$form['founder']['add_officer']['individual'] = array(
'#type' => 'textfield',
'#title' => t('Individual'),
'#states' => array(
'visible' => array(
':input[name="founder_type"' => array('value' => "individual"),
),
),
);
$form['founder']['add_officer']['corporation'] = array(
'#type' => 'textfield',
'#title' => t('Corporation'),
'#states' => array(
'visible' => array(
':input[name="founder_type"' => array('value' => "corporate"),
),
),
);
return $form;
}
Place $ sign at line no 2
$form = array();