Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
звіт по парктиці1.doc
Скачиваний:
4
Добавлен:
21.12.2018
Размер:
388.61 Кб
Скачать
  1. Постановка задачі та звіт виконання індивідуальних завдань з технології розробки програмного забезпечення та охорони праці

  1. Постановка задачі.

На ТОВ «Інтернетдевелс», я був одним з програмістів які розробляли сайт міської ради. Сайт розроблявся на базі CMF Drupal. Я встановлював і налаштовував потрібні моудулі а також, написав свій модуль для певних потреб сайту:

<?php

// $Id miskrada_custom.module $

//The default value id for factions vocabulary .

define('FACTIONS_VOCABULARY', 5);

//The default value id for district vocabulary .

define('DISTRICT_VOCABULARY', 6);

/**

* Implementation of hook_menu

*/

function miskrada_custom_menu() {

$items['factions'] = array(

'title' => 'Factions',

'page callback' => 'miskrada_custom_factions',

'access callback' => TRUE,

'access arguments' => TRUE,

'type' => MENU_CALLBACK,

);

return $items;

}

/**

* Implementation of hook_cronapi

*/

function miskrada_custom_cronapi($op, $job = NULL) {

switch ($op) {

case 'list':

return array(

//'miskrada_poll' => 'Add one like to poll of new site',

);

case 'rule':

//if ($job == 'miskrada_poll') {

// return '*/5 * * * *';

//}

return '0 1 * * *';

case 'execute':

//if ($job == 'miskrada_poll') {

// db_insert('poll_vote')->fields(array(

// 'nid' => 988,

// 'chid' => 32,

// 'uid' => REQUEST_TIME,

// 'hostname' => '127.0.0.1',

// 'timestamp' => REQUEST_TIME,

// ))->execute();

//

// // Add one to the votes.

// db_update('poll_choice')

// ->expression('chvotes', 'chvotes + 1')

// ->condition('chid', 32)

// ->execute();

//}

}

}

/**

* Implementation of hook_init

*/

function miskrada_custom_init() {

global $user;

if ($user->uid != 1 && arg(0) == 'admin' && arg(1) == 'people' && arg(2) == 'permissions') {

drupal_goto('<front>');

}

$print_css = variable_set('print_css', '%t/styles/print.css');

if ((arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'menu' && !arg(3)) && $user->uid != 1) {

drupal_goto('<front>');

}

if ((arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'menu' && arg(3) == 'manage' && arg(4) != 'menu-right-menu-citizen') && $user->uid != 1) {

drupal_goto('<front>');

}

if (arg(0) == 'deputy' && arg(1)) {

if (arg(1) != 'factions') {

drupal_not_found();

}

}

//if (http://www.lutsk.ua/admin/structure/block/manage/block/39/configure) {

//

//}

}

/**

* Implementation of hook_form_alter

*/

function miskrada_custom_form_alter(&$form, &$form_state, $form_id) {

if ($form['#id'] == 'views-exposed-form-deputy-page') {

$vocabulary = taxonomy_get_tree(DISTRICT_VOCABULARY);

foreach ($vocabulary as $vocabulary) {

$districts[$vocabulary->tid] = $vocabulary->name;

}

unset($form['field_person_district_tid'], $form['field_person_faction_tid']);

$factions = miskrada_custom_options_factions();

$factions[''] = t('all Factions');

$districts[''] = t('all Districts');

$form['field_person_faction_tid'] = array(

'#type' => 'select',

'#title' => t('Faction'),

'#options' => $factions,

);

$form['field_person_district_tid'] = array(

'#type' => 'select',

'#title' => t('District'),

'#options' => $districts,

);

}

switch ($form_id) {

case 'block_custom_block_delete';

case 'menu_block_delete';

case 'block_add_block_form':

case 'block_admin_display_form':

global $user;

if ($user->uid != 1) {

drupal_goto('<front>');

}

break;

case 'block_admin_configure':

if (!in_array($form['delta']['#value'], array(39, 40))) {

drupal_goto('<front>');

}

break;

case 'user_profile_form':

case 'user_register_form':

$form['#pre_render'][] = 'miskrada_user_register_form_prerender';

unset($form['locale']);

break;

case 'webform_client_form_621':

$form['#pre_render'][] = 'miskrada_custom_webform_client_form_605_prerender';

$form['submitted']['select']['#title'] = '';

$form['submitted']['fizichna_osoba']['#title'] = '';

$form['submitted']['yuridichna_osoba_chi_obiednannya_gromadyan']['#title'] = '';

break;

case 'taxonomy_form_term':

unset($form['relations']);

break;

case 'webform_client_form_605':

array_unshift($form['#submit'], 'miskrada_custom_get_mail');

$form['#pre_render'][] = 'miskrada_custom_webform_client_form_605_prerender';

$tree = taxonomy_get_tree(FACTIONS_VOCABULARY);

foreach ($tree as $tree) {

$factions[$tree->tid] = $tree->name;

}

$query = db_select('taxonomy_index', 'n')->fields('n');

$result = $query->execute();

while ($record = $result->fetchAssoc()) {

$tree = taxonomy_get_tree(FACTIONS_VOCABULARY);

foreach ($tree as $tree) {

if ($tree->tid == $record['tid']) {

$node = node_load($record['nid']);

$deputy[$record['tid']][$node->nid] = $node->title;

}

}

}

foreach ($deputy as $key => $value) {

asort($value);

$person[$key] = $value;

}

unset($deputy);

$deputy = $person;

$i = 0;

foreach ($deputy as $key => $deputy) {

foreach ($deputy as $deputy) {

$sort[$key][$i] = $deputy;

$i++;

}

}

drupal_add_js(array('miskrada' => array('deputy' => $sort )), 'setting');

break;

case 'webform_client_form_164':

array_unshift($form['#submit'], 'miskrada_custom_get_mail_164');

$form['#pre_render'][] = 'miskrada_custom_webform_client_form_605_prerender';

break;

case 'comment_node_prescription_form':

case 'comment_node_page_form':

unset($form['author']);

$form['subject']['#title'] = t('Author');

unset($form['actions']['preview']);

$form['#pre_render'][] = 'miskrada_custom_webform_client_form_605_prerender';

break;

}

}

/**

* Prerender function for translate role

*/

function miskrada_user_register_form_prerender($form) {

foreach ($form['account']['roles'] as $key => $roles) {

if (is_numeric($key)) {

$form['account']['roles'][$key]['#title'] = t($roles['#title']);

}

}

return $form;

}

/**

* Prerender function for filter capcha element

*/

function miskrada_custom_webform_client_form_605_prerender($form) {

unset($form['actions']['captcha']['captcha_widgets']['captcha_response']['#title'],

$form['actions']['captcha']['captcha_widgets']['captcha_response']['#description'],

$form['actions']['captcha']['#name']);

return $form;

}

/**

* Implementation of hook_webform_select_options_info().

* See webform/webform_hooks.php for further information on this hook in the Webform API.

*/

function miskrada_custom_webform_select_options_info() {

$items['one_onehundred'] = array(

'title' => t('departments'),

'options callback' => 'miskrada_custom_options_departments',

);

$items['factions'] = array(

'title' => t('factions'),

'options callback' => 'miskrada_custom_options_factions',

);

$items['deputy'] = array(

'title' => t('deputy'),

'options callback' => 'miskrada_custom_options_deputy',

);

$items['factions_group'] = array(

'title' => t('Factions and Group'),

'options callback' => 'miskrada_custom_options_factions_group',

);

return $items;

}

/**

* Function page factions

*/

function miskrada_custom_factions() {

$tree = taxonomy_get_tree(FACTIONS_VOCABULARY);

foreach ($tree as $tree) {

$tid = $tree->tid;

$tname = $tree->name;

$links = l($tname, 'deputy/factions/' . $tid, array('attributes' => array('class' => 'link-faction')));

$link[] = render($links);

}

$vars = array(

'title' => '',

'items' => $link,

'type' => 'ul',

'attributes' => array('class' => 'factions'),

);

$links = theme_item_list($vars);

return $links;

}

/**

* Build options for departments.

*/

function miskrada_custom_options_departments() {

global $language;

$options[] = t('Group to respond quickly 15-80');

$options[] = t('Mayor');

$options[] = t('Kravchuk Svyatoslav');

$options[] = t('Verbych Yuri Grigorovich');

$options[] = t('Sokolovsky Larisa');

$query = db_select('node', 'n')->condition('type', 'departments')->fields('n');

$result = $query->execute();

while ($record = $result->fetchAssoc()) {

if ($record['language'] == $language->language) {

$options[] = $record['title'];

}

}

return $options;

}

/**

* Build options for factions and deuty group.

*/

function miskrada_custom_options_factions_group() {

$tree = taxonomy_get_tree(FACTIONS_VOCABULARY);

foreach ($tree as $tree) {

$options[$tree->tid] = $tree->name;

}

$query = db_select('node', 'n');

$query->condition('type', 'deputy_group');

$query->fields('n');

$result = $query->execute();

while ($record = $result->fetchAssoc()) {

$options[$record['nid']] = $record['title'];

}

return $options;

}

/**

* Build options for factions.

*/

function miskrada_custom_options_factions() {

$tree = taxonomy_get_tree(FACTIONS_VOCABULARY);

foreach ($tree as $tree) {

$options[$tree->tid] = $tree->name;

}

return $options;

}

/**

* Build options for deputy.

*/

function miskrada_custom_options_deputy() {

$tree = miskrada_custom_options_factions();

$query = db_select('taxonomy_index', 'n')->fields('n');

$result = $query->execute();

while ($record = $result->fetchAssoc()) {

$tree = taxonomy_get_tree(FACTIONS_VOCABULARY);

foreach ($tree as $tree) {

if ($tree->tid == $record['tid']) {

$node = node_load($record['nid']);

$deputy[$record['tid']][$node->nid] = $node->title;

}

}

}

foreach ($deputy as $key => $value) {

asort($value);

$person[$key] = $value;

}

unset($deputy);

$deputy = $person;

$i = 0;

foreach ($deputy as $key => $deputy) {

foreach ($deputy as $deputy) {

$sort[$key][$i] = $deputy;

$i++;

}

}

foreach ($sort as $sort) {

foreach ($sort as $sort) {

$options[] = $sort;

}

}

return $options;

}

/**

* Function submit for get mail from nodes deputy

*/

function miskrada_custom_get_mail($form, &$form_state) {

global $user;

$default_mail = $form_state['complete form']['#node']->webform['emails'][1]['email'];

$tree = miskrada_custom_options_factions();

$query = db_select('taxonomy_index', 'n')->fields('n');

$result = $query->execute();

while ($record = $result->fetchAssoc()) {

$tree = taxonomy_get_tree(FACTIONS_VOCABULARY);

foreach ($tree as $tree) {

if ($tree->tid == $record['tid']) {

$node = node_load($record['nid']);

$deputy[$record['tid']][$node->nid] = $node->title;

if (!empty($node->field_person_email[$node->language][0]['email'])) {

$deputy[$record['tid']][$node->nid] = $node->title . '|' . $node->field_person_email[$node->language][0]['email'];

}

else {

$deputy[$record['tid']][$node->nid] = $node->title . '|' . $default_mail;

}

}

}

}

foreach ($deputy as $key => $value) {

asort($value);

$person[$key] = $value;

}

unset($deputy);

$deputy = $person;

$i = 0;

foreach ($deputy as $key => $deputy) {

foreach ($deputy as $deputy) {

$sort[$key][$i] = $deputy;

$i++;

}

}

foreach ($sort as $sort) {

foreach ($sort as $sort) {

$options[] = $sort;

}

}

$node = node_load($form_state['values']['submitted']['frakciya']);

if ($node->type == 'deputy_group') {

$field = field_get_items('node', $node, 'field_deputy_group');

foreach ($field as $key => $value) {

$nids[] = $value['nid'];

}

$field = field_get_items('node', $node, 'field_deputy_group_head');

$nids[] = $field[0]['nid'];

$query = db_select('node', 'n');

$query->condition('nid', $nids, 'IN');

$query->Join('field_data_field_person_email', 'f', 'f.entity_id = n.nid');

$query->addField('f', 'field_person_email_email', 'nids');

$result = $query->execute();

while ($record = $result->fetchAssoc()) {

$mails = $record['nids'];

$module = 'internetdevels';

$key = '';

$message = drupal_mail($module, $key, $mails, language_default(), array(), 'lutsk.ua', FALSE);

$message['body'][] = t('Sended: !date', array('!date' => format_date(REQUEST_TIME, 'custom', 'D, d/m/Y - H:i')));

$message['body'][] = t('Deputy group') . ': ' . $node->title;

$message['body'][] = $form_state['complete form']['#node']->webform['components'][2]['name'] . ': ' . $form_state['values']['submitted']['prizvishche_imya_po_batkovi'];

$message['body'][] = $form_state['complete form']['#node']->webform['components'][3]['name'] . ': ' . $form_state['values']['submitted']['kontaktniy_telefon'];

$message['body'][] = $form_state['complete form']['#node']->webform['components'][4]['name'] . ': ' . $form_state['values']['submitted']['adresa'];

$message['body'][] = $form_state['complete form']['#node']->webform['components'][5]['name'] . ': ' . $form_state['values']['submitted']['adresa_elektronnoyi_poshti'];

$message['body'][] = $form_state['complete form']['#node']->webform['components'][6]['name'] . ': ' . $form_state['values']['submitted']['tekst_zapitannya'];

$system = drupal_mail_system($module, $key);

// Format the message body.

$message = $system->format($message);

// Send e-mail.

$message['result'] = $system->mail($message);

}

}

else {

if (!empty($form_state['input']['submitted']['do_kogo_zapitannya'])) {

$key = $form_state['input']['submitted']['do_kogo_zapitannya'];

preg_match('/\|(.*)/', $options[$key], $mail);

$form_state['complete form']['#node']->webform['emails'][1]['email'] = $mail[1];

}

}

}

/**

* Functions submit for webform_client_form_164

*/

function miskrada_custom_get_mail_164($form, &$form_state) {

$nid = $form_state['input']['submitted']['do_kogo_zapitannya'];

$query = db_select('field_data_field_departments_mail', 'n')->fields('n');

$result = $query->execute();

while ($record = $result->fetchAssoc()) {

if ($record['entity_id'] == $nid) {

$mail = $record['field_departments_mail_email'];

}

}

if (isset($mail) && !empty($mail)) {

$form_state['complete form']['#node']->webform['emails'][1]['email'] = $mail;

}

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]