--- db/prgsrc/drupal/modules/chgk_db/chgk_db.module 2010/03/20 17:23:42 1.3 +++ db/prgsrc/drupal/modules/chgk_db/chgk_db.module 2010/04/24 21:45:49 1.6 @@ -6,18 +6,68 @@ *********************/ require_once(dirname(__FILE__)."/classes/DbPackage.class.php"); +require_once(dirname(__FILE__)."/classes/DbEditors.class.php"); /** * Implementation of hook_menu(). */ function chgk_db_menu() { - $items['print'] = array( +#print_r(debug_backtrace()); + $items['tour/%/view'] = array( + 'title' => 'Читать', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 0 + ); + + $items['tour/%/print'] = array( 'path' => 'print', + 'title' => 'Печатать', 'page callback' => 'chgk_db_print', 'page arguments' => array(1), 'access callback' => "chgk_db_access", + 'access arguments' => array(1, 'print'), + 'localized_options' => array('attributes' => array('target'=>'_blank')), + 'type' => MENU_LOCAL_TASK, + 'weight' => 1 + ); + + + $items['tour/%/fb2'] = array( + 'path' => 'tour/%/fb2', + 'title' => 'FB2', + 'page callback' => 'chgk_db_fb2', + 'page arguments' => array(1), + 'access callback' => "chgk_db_access", + 'access arguments' => array(1, 'fb2'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2 + ); + $items['tree'] = array( + 'path' => 'tree', + 'title' => 'Все турниры', + 'page callback' => 'chgk_db_tree', + 'access callback' => "chgk_db_access", + 'type' => MENU_NORMAL_ITEM + ); + + $items['editors'] = array( + 'path' => 'editors', + 'title' => 'Редакторы', + 'page callback' => 'chgk_db_editors', + 'access callback' => "chgk_db_access", + 'type' => MENU_NORMAL_ITEM + ); + + $items['tour'] = array( + 'path' => 'tour', + 'page callback' => 'chgk_db_tour', + 'page arguments' => array(1), + 'access callback' => "chgk_db_access" + ); + + return $items; } @@ -28,7 +78,10 @@ function chgk_db_theme() { $items['chgk_db_print'] = array( 'arguments' => array( 'title' =>'', - 'content' => '' + 'content' => '', + 'link' => '' + + ), 'template'=>'templates/chgk_db_print' ); @@ -45,6 +98,23 @@ function chgk_db_theme() { 'template'=>'templates/chgk_db_tour' ); + $items['chgk_db_tour_fb2'] = array( + 'arguments' => array( + 'tour'=>NULL, + 'alone' => TRUE + ), + 'template'=>'templates/chgk_db_tour_fb2' + ); + + $items['chgk_db_tours_fb2'] = array( + 'arguments' => array( + 'tournament'=>'', + ), + 'template'=>'templates/chgk_db_tours_fb2' + ); + + + $items['chgk_db_question'] = array( 'arguments' => array( 'question'=>NULL @@ -52,6 +122,14 @@ function chgk_db_theme() { 'template'=>'templates/chgk_db_question' ); + $items['chgk_db_question_fb2'] = array( + 'arguments' => array( + 'question'=>NULL + ), + 'template'=>'templates/chgk_db_question_fb2' + ); + + $items['chgk_db_jeopardy_question'] = array( 'arguments' => array( 'question'=>NULL @@ -65,6 +143,10 @@ function chgk_db_theme() { ), 'template'=>'templates/chgk_db_champ_full' ); + $items['chgk_db_fb2'] = array( + 'arguments' => array('tournament'=>''), + 'template' => 'templates/chgk_db_fb2' + ); return $items; } @@ -73,7 +155,113 @@ function chgk_db_print($string) { print $tournament->getPrintVersion(); } +function chgk_db_tour($name) { + if (empty($name)) { + $tournament = DbPackage::newRoot(); + } else { + $tournament = DbPackage::newFromDb($name); + } + drupal_set_title($tournament->getFullTitle()); + $breadcrumb = array_merge(drupal_get_breadcrumb(),$tournament->getBreadcrumb()); + drupal_set_breadcrumb($breadcrumb); + return $tournament->getHtmlContent(); +} + +function chgk_db_tree() { + $class = DbPackage::newRoot(); + $class -> loadTree(); + drupal_set_title('Все турниры'); +# $breadcrumb = array_merge(drupal_get_breadcrumb(),$tournament->getBreadcrumb()); + drupal_set_breadcrumb($breadcrumb); + + return $class->htmlTree()."\n"; +} -function chgk_db_access() { +function chgk_db_fb2($string) { + $tournament = DbPackage::newFromDb($string); + $xml = $tournament->getFb2(); + if (!$xml) { + print "Something is wrong :("; + exit; + } + $filename = "$string.fb2"; + $zipname = $filename.".zip"; + + header("Content-Type: application/octet-stream\n"); + header("Content-Type: application/force-download\n"); + header("Content-Type: application/download\n"); + header("Content-Type: application/x-zip-compressed; name=$filename\n"); + header("Content-Disposition: attachment; filename=$filename.zip \n"); + chdir(file_directory_temp()); + $f = fopen ($filename, "w"); + fputs($f, $xml); + fclose($f); + system("zip $zipname $filename>/dev/null"); + print passthru("cat $zipname"); + exit; +} + + +function chgk_db_access($tour=NULL, $action ='') { + if ($action == 'fb2') { + $tournament = DbPackage::newFromDb($tour); + if (!$tournament->hasFb2()) { + return FALSE; + } + } elseif ($action == 'print') { + $tournament = DbPackage::newFromDb($tour); + if (!$tournament->hasPrintVersion()) { + return FALSE; + } + } return TRUE; -} \ No newline at end of file +} + +function chgk_db_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) { + if ($op == 'name') { + return 'Вопросы'; + } elseif( $op == 'search') { + $db = new DbDatabase(); + $res = $db->getFulltextSearchRes($keys); + $factory = new DbQuestionFactory(); + + while($a = db_fetch_object($res)) { + $q = $factory->getQuestion($a); + $q->setSearchString($keys); + $results[] = array( + 'link' => $q->getUrl(), + 'title' => $q->getSearchTitle(), + 'snippet' => $q->getHtml() + ); + } + return $results; + + } + return true; +} + + function chgk_db_form_alter(&$form, &$form_state) { + if ($form['#submit'][0] == 'search_box_form_submit') { + $form['#submit'][] = 'chgk_db_search_box_submit'; + } + } +function chgk_db_editors() { + if ($id = arg(1)) { + $author = new DbEditor($id); + drupal_set_title($author->getFullName()); + $breadcrumb = array_merge( + drupal_get_breadcrumb(), + $author->getBreadcrumb()); + drupal_set_breadcrumb($breadcrumb); + + return $author->getHtmlPage(); + } else { + $authorsEngine = new DbEditors(); + return $authorsEngine->getAllHtml(); + } + } + +function chgk_db_search_box_submit($form, &$form_state) { + $form_id = $form['form_id']['#value']; + $form_state['redirect'] = 'search/chgk_db/'. trim($form_state['values'][$form_id]); +}