summaryrefslogtreecommitdiff
path: root/lab_migration.module
blob: 4941d5a3907ec907e69e4003917eb2a17c6054b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
// $Id$

/**
 * Implementation of hook_menu().
 */
function lab_migration_menu()
{
  $items = array();

  $items['lab_migration/proposal'] = array(
    'title' => 'Lab Migration Proposal',
    'description' => 'Lab Migration Proposal', 
    'page callback' => 'drupal_get_form',
    'page arguments' => array('lab_migration_proposal_form'),
    'access arguments' => array('create proposal'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'proposal.inc',
  );

  $items['lab_migration/labs'] = array(
    'title' => 'Migrated Labs',
    'description' => 'Migrated Labs', 
    'page callback' => 'migrated_labs',
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'migrated_labs.inc',
  );

  /* for reviewers */
  $items['lab_migration/manage_proposal'] = array(
    'title' => 'Manage Lab Migration',
    'description' => 'Manage Lab Migration Proposals',
    'page callback' => '_proposal_pending',
    'access callback' => 'user_access',
    'access arguments' => array('manage proposal'),
    'file' => 'manage_proposal.inc',
  );
  $items['lab_migration/manage_proposal/pending'] = array(
    'title' => 'Pending Proposals',
    'description' => 'Pending Lab Migration Proposals Queue',
    'page callback' => '_proposal_pending',
    'access callback' => 'user_access',
    'access arguments' => array('manage proposal'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 1,
    'file' => 'manage_proposal.inc',
  );
  $items['lab_migration/manage_proposal/pending_solution'] = array(
    'title' => 'Pending Solution',
    'description' => 'Pending Lab Migration Solution',
    'page callback' => '_proposal_pending_solution',
    'access callback' => 'user_access',
    'access arguments' => array('manage proposal'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 2,
    'file' => 'solution.inc',
  );
  $items['lab_migration/manage_proposal/all'] = array(
    'title' => 'All Proposals',
    'description' => 'All Proposals',
    'page callback' => '_proposal_all',
    'access callback' => 'user_access',
    'access arguments' => array('manage proposal'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 3,
    'file' => 'manage_proposal.inc',
  );
  $items['lab_migration/manage_proposal/approve'] = array(
    'title' => 'Approve Proposal',
    'description' => 'Approve Proposal',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('proposal_approval_form'),
    'access arguments' => array('manage proposal'),
    'type' => MENU_CALLBACK,
    'file' => 'manage_proposal.inc',
  );
  $items['lab_migration/manage_proposal/edit'] = array(
    'title' => 'Edit Proposal',
    'description' => 'Edit Proposal',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('proposal_edit_form'),
    'access arguments' => array('manage proposal'),
    'type' => MENU_CALLBACK,
    'file' => 'manage_proposal.inc',
  );
  $items['lab_migration/manage_proposal/solution'] = array(
    'title' => 'Proposal Solution',
    'description' => 'Proposal Solution',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('proposal_solution_form'),
    'access arguments' => array('manage proposal'),
    'type' => MENU_CALLBACK,
    'file' => 'solution.inc',
  );

  /* for admin */
  $items['admin/settings/lab_migration'] = array(
    'title' => 'Lab Migration Settings',
    'description' => 'Lab Migration Settings', 
    'page callback' => 'drupal_get_form',
    'page arguments' => array('lab_migration_settings_form'),
    'access arguments' => array('administer lab migration'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'settings.inc',
  );

  return $items;
}

/**
 * Implementation of hook_perm().
 */
function lab_migration_perm()
{
  return array('create proposal', 'manage proposal', 'administer lab migration');
}

/**
 * Implementation of hook_mail().
 */
function lab_migration_mail($key, &$message, $params)
{
  global $user;
  $language = $message['language'];
  switch ($key) {
    case 'proposal_received':
      /* initializing data */
      $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']);
      $proposal_data = db_fetch_object($proposal_q);
      $user_data = user_load($params['proposal_received']['user_id']);
 
      $message['subject'] = t('[!site_name] Your Lab migration proposal has been received', array('!site_name' => variable_get('site_name', '')), $language->language);
      $message['body'] = t('
Dear !user_name,

We have received your proposal to migrate the lab in to Scilab, following details was submitted by you:

Name of the Proposer : ' . $proposal_data->name_title . ' ' . $proposal_data->name . '
Email : ' . $user_data->mail . '
Contact Phone No. : ' . $proposal_data->contact_ph . '
Department/Branch : ' . $proposal_data->department . '
University/Institute : ' .  $proposal_data->university . '
Title of the Lab : ' . $proposal_data->lab_title . '
Topic of the Problem : ' .  $proposal_data->problem_topic . '

Your proposal is under review and you will soon receive an email from us regarding the same.

Best Wishes,

Lab Migration Team
!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
      break;

    case 'proposal_disapproved':
      /* initializing data */
      $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['proposal_disapproved']['proposal_id']);
      $proposal_data = db_fetch_object($proposal_q);
      $user_data = user_load($params['proposal_disapproved']['user_id']);

      $message['subject'] = t('[!site_name] Your Lab migration proposal has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language);
      $message['body'] = t('
Dear !user_name,

Your following Lab migration proposal has been disapproved:

Reason for disapproval: ' . $proposal_data->message . '

Name of the Proposer : ' . $proposal_data->name_title . ' ' . $proposal_data->name . '
Email : ' . $user_data->mail . '
Contact Phone No. : ' . $proposal_data->contact_ph . '
Department/Branch : ' . $proposal_data->department . '
University/Institute : ' .  $proposal_data->university . '
Title of the Lab : ' . $proposal_data->lab_title . '
Topic of the Problem : ' .  $proposal_data->problem_topic . '

Best Wishes,

Lab Migration Team
!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
      break;

    case 'proposal_approved':
      /* initializing data */
      $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']);
      $proposal_data = db_fetch_object($proposal_q);
      $user_data = user_load($params['proposal_approved']['user_id']);

      $message['subject'] = t('[!site_name] Your Lab migration proposal has been approved', array('!site_name' => variable_get('site_name', '')), $language->language);
      $message['body'] = t('
Dear !user_name,

Your following Lab migration proposal has been approved and solution is in progress. You will receive an email from us as soon as we will upload the solution. Please note that your solution will be made available on the Scilab portal.

Name of the Proposer : ' . $proposal_data->name_title . ' ' . $proposal_data->name . '
Email : ' . $user_data->mail . '
Contact Phone No. : ' . $proposal_data->contact_ph . '
Department/Branch : ' . $proposal_data->department . '
University/Institute : ' .  $proposal_data->university . '
Title of the Lab : ' . $proposal_data->lab_title . '
Topic of the Problem : ' .  $proposal_data->problem_topic . '

Best Wishes,

Lab Migration Team
!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
      break;

    case 'standard':
      $message['subject'] = $params['standard']['subject'];
      $message['body'] = $params['standard']['body'];
      break;
  }
}

/******************************************************************************/
/**************************** GENERAL FUNCTION ********************************/
/******************************************************************************/

function lab_migration_path()
{
  return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'sites/default/files/lab_migration/';
}

/******************************************************************************/
/*************************** VALIDATION FUNCTIONS *****************************/
/******************************************************************************/

function lab_migration_check_valid_filename($file_name)
{
  if (!preg_match('/^[0-9a-zA-Z\_\.\-]+$/', $file_name))
    return FALSE;
  else
    if (substr_count($file_name, ".") > 1)
      return FALSE;
    else
      return TRUE;
}