Annotation of db/prgsrc/drupal/modules/chgk_db/chgk_db.module, revision 1.6

1.1       roma7       1: <?php
                      2: /**********************
                      3: *
                      4: * Tournament
                      5: *
                      6: *********************/
                      7: 
                      8: require_once(dirname(__FILE__)."/classes/DbPackage.class.php");
1.6     ! roma7       9: require_once(dirname(__FILE__)."/classes/DbEditors.class.php");
1.1       roma7      10: 
                     11: 
                     12: /**
                     13:  * Implementation of hook_menu().
                     14:  */
                     15: function chgk_db_menu() {
1.6     ! roma7      16: #print_r(debug_backtrace());
        !            17:   $items['tour/%/view'] = array(
        !            18:     'title' => 'Читать',
        !            19:     'type' => MENU_DEFAULT_LOCAL_TASK,
        !            20:     'weight' => 0
        !            21:   );
        !            22: 
        !            23:   $items['tour/%/print'] = array(
1.1       roma7      24:     'path'  => 'print',
1.6     ! roma7      25:     'title' => 'Печатать',
1.1       roma7      26:     'page callback' => 'chgk_db_print',
1.2       roma7      27:     'page arguments' => array(1),
1.1       roma7      28:     'access callback' => "chgk_db_access",
1.6     ! roma7      29:     'access arguments' => array(1, 'print'),
        !            30:     'localized_options' => array('attributes' => array('target'=>'_blank')),
        !            31:     'type' => MENU_LOCAL_TASK,
        !            32:     'weight' => 1    
1.1       roma7      33:   );
1.6     ! roma7      34: 
        !            35:   
        !            36:   $items['tour/%/fb2'] = array(
        !            37:     'path'  => 'tour/%/fb2',
        !            38:     'title' => 'FB2',
1.4       roma7      39:     'page callback' => 'chgk_db_fb2',
                     40:     'page arguments' => array(1),
                     41:     'access callback' => "chgk_db_access",
1.6     ! roma7      42:     'access arguments' => array(1, 'fb2'),    
        !            43:     'type' => MENU_LOCAL_TASK,
        !            44:     'weight' => 2
        !            45:     
        !            46:   );
        !            47:   $items['tree'] = array(
        !            48:       'path' => 'tree',
        !            49:       'title' => 'Все турниры',
        !            50:       'page callback' => 'chgk_db_tree',
        !            51:       'access callback' => "chgk_db_access",
        !            52:       'type' => MENU_NORMAL_ITEM      
        !            53:   );
        !            54: 
        !            55:   $items['editors'] = array(
        !            56:       'path' => 'editors',
        !            57:       'title' => 'Редакторы',
        !            58:       'page callback' => 'chgk_db_editors',
        !            59:       'access callback' => "chgk_db_access",
        !            60:       'type' => MENU_NORMAL_ITEM      
        !            61:   );
        !            62: 
        !            63:   $items['tour'] = array(
        !            64:       'path' => 'tour',
        !            65:       'page callback' => 'chgk_db_tour',
        !            66:       'page arguments' => array(1),
        !            67:       'access callback' => "chgk_db_access"
1.4       roma7      68:   );
1.6     ! roma7      69:   
        !            70:   
1.1       roma7      71:   return $items;
                     72: }
                     73: 
                     74: /**
                     75:  * Implementation of hook_theme().
                     76:  */
                     77: function chgk_db_theme() {
                     78:   $items['chgk_db_print'] = array(
                     79:     'arguments' => array(
                     80:       'title' =>'',
1.6     ! roma7      81:       'content' => '',
        !            82:       'link' => ''
        !            83:       
        !            84:       
1.1       roma7      85:     ),
                     86:     'template'=>'templates/chgk_db_print' 
                     87:   );
                     88:   $items['chgk_db_field'] = array(
                     89:     'arguments' => array(
                     90:       'field' => NULL
                     91:     )  
                     92:   );
                     93:   $items['chgk_db_tour'] = array(
                     94:     'arguments' => array(
1.3       roma7      95:       'tour'=>NULL,
                     96:       'alone' => TRUE
1.1       roma7      97:     ),
                     98:     'template'=>'templates/chgk_db_tour'
                     99:   );
                    100: 
1.4       roma7     101:   $items['chgk_db_tour_fb2'] = array(
                    102:     'arguments' => array(
                    103:       'tour'=>NULL,
                    104:       'alone' => TRUE
                    105:     ),
                    106:     'template'=>'templates/chgk_db_tour_fb2'
                    107:   );
                    108: 
1.6     ! roma7     109:   $items['chgk_db_tours_fb2'] = array(
        !           110:     'arguments' => array(
        !           111:       'tournament'=>'',
        !           112:     ),
        !           113:     'template'=>'templates/chgk_db_tours_fb2'
        !           114:   );
        !           115: 
        !           116: 
1.4       roma7     117: 
1.1       roma7     118:   $items['chgk_db_question'] = array(
                    119:     'arguments' => array(
1.2       roma7     120:       'question'=>NULL
1.1       roma7     121:     ),
                    122:     'template'=>'templates/chgk_db_question'
1.2       roma7     123:   );
                    124: 
1.4       roma7     125:   $items['chgk_db_question_fb2'] = array(
                    126:     'arguments' => array(
                    127:       'question'=>NULL
                    128:     ),
                    129:     'template'=>'templates/chgk_db_question_fb2'
                    130:   );
                    131: 
                    132: 
1.3       roma7     133:   $items['chgk_db_jeopardy_question'] = array(
                    134:     'arguments' => array(
                    135:       'question'=>NULL
                    136:     ),
                    137:     'template'=>'templates/chgk_db_jeopardy_question'
                    138:   );
                    139: 
1.2       roma7     140:   $items['chgk_db_champ_full'] = array(
                    141:     'arguments' => array(
                    142:         'tour' => NULL
                    143:     ),
                    144:     'template'=>'templates/chgk_db_champ_full'
                    145:   );
1.4       roma7     146:   $items['chgk_db_fb2'] = array(
                    147:       'arguments' => array('tournament'=>''),
                    148:       'template' => 'templates/chgk_db_fb2'
                    149:   );
1.1       roma7     150:   return $items;
                    151: }
                    152: 
                    153: function chgk_db_print($string) {
1.2       roma7     154:   $tournament = DbPackage::newFromDb($string);
                    155:   print $tournament->getPrintVersion();
1.1       roma7     156: }
                    157: 
1.6     ! roma7     158: function chgk_db_tour($name) {
        !           159:   if (empty($name)) {
        !           160:     $tournament = DbPackage::newRoot();    
        !           161:   } else {
        !           162:     $tournament = DbPackage::newFromDb($name);
        !           163:   }
        !           164:   drupal_set_title($tournament->getFullTitle());
        !           165:   $breadcrumb = array_merge(drupal_get_breadcrumb(),$tournament->getBreadcrumb());
        !           166:   drupal_set_breadcrumb($breadcrumb);
        !           167:   return $tournament->getHtmlContent();
        !           168: }
        !           169: 
        !           170: function chgk_db_tree() {        
        !           171:   $class = DbPackage::newRoot();
        !           172:   $class -> loadTree();
        !           173:   drupal_set_title('Все турниры');
        !           174: #  $breadcrumb = array_merge(drupal_get_breadcrumb(),$tournament->getBreadcrumb());
        !           175:   drupal_set_breadcrumb($breadcrumb);
        !           176:     
        !           177:     return $class->htmlTree()."\n";
        !           178: }
        !           179: 
1.4       roma7     180: function chgk_db_fb2($string) {
                    181:   $tournament = DbPackage::newFromDb($string);
1.6     ! roma7     182:   $xml = $tournament->getFb2();
        !           183:   if (!$xml) {
        !           184:      print "Something is wrong :(";
        !           185:      exit;
        !           186:   }
1.5       roma7     187:   $filename = "$string.fb2"; 
                    188:   $zipname = $filename.".zip";
                    189:   
                    190:   header("Content-Type: application/octet-stream\n");
                    191:   header("Content-Type: application/force-download\n");
                    192:   header("Content-Type: application/download\n");
                    193:   header("Content-Type: application/x-zip-compressed; name=$filename\n");
                    194:   header("Content-Disposition: attachment; filename=$filename.zip \n");
                    195:   chdir(file_directory_temp());
                    196:   $f = fopen ($filename, "w");
                    197:   fputs($f, $xml);
                    198:   fclose($f);
                    199:   system("zip $zipname $filename>/dev/null");
                    200:   print passthru("cat $zipname");
1.4       roma7     201:   exit;
                    202: }
                    203: 
1.1       roma7     204: 
1.6     ! roma7     205: function chgk_db_access($tour=NULL, $action ='') {
        !           206:   if ($action == 'fb2') {
        !           207:     $tournament = DbPackage::newFromDb($tour);
        !           208:     if (!$tournament->hasFb2()) {
        !           209:       return FALSE;
        !           210:     }
        !           211:   } elseif ($action == 'print') {
        !           212:     $tournament = DbPackage::newFromDb($tour);  
        !           213:     if (!$tournament->hasPrintVersion()) {
        !           214:       return FALSE;
        !           215:     }  
        !           216:   }
1.1       roma7     217:   return TRUE;
1.6     ! roma7     218: }
        !           219: 
        !           220: function chgk_db_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) {
        !           221:   if ($op == 'name') {
        !           222:     return 'Вопросы';
        !           223:   } elseif( $op == 'search') {
        !           224:      $db = new DbDatabase();
        !           225:      $res = $db->getFulltextSearchRes($keys);
        !           226:      $factory = new DbQuestionFactory();
        !           227: 
        !           228:      while($a = db_fetch_object($res)) {
        !           229:         $q = $factory->getQuestion($a);
        !           230:         $q->setSearchString($keys);
        !           231:         $results[] = array(
        !           232:           'link' => $q->getUrl(),
        !           233:           'title' => $q->getSearchTitle(),
        !           234:           'snippet' => $q->getHtml()
        !           235:         );
        !           236:     }
        !           237:     return $results;
        !           238: 
        !           239:   }
        !           240:   return true;
        !           241: }
        !           242: 
        !           243:   function chgk_db_form_alter(&$form, &$form_state) {
        !           244:     if  ($form['#submit'][0] == 'search_box_form_submit') {        
        !           245:         $form['#submit'][] = 'chgk_db_search_box_submit';
        !           246:     }
        !           247:   }
        !           248: function chgk_db_editors() {
        !           249:     if ($id = arg(1)) {
        !           250:         $author = new DbEditor($id);
        !           251:         drupal_set_title($author->getFullName());
        !           252:       $breadcrumb = array_merge(
        !           253:               drupal_get_breadcrumb(),
        !           254:               $author->getBreadcrumb());
        !           255:         drupal_set_breadcrumb($breadcrumb);
        !           256: 
        !           257:         return $author->getHtmlPage();
        !           258:     } else {
        !           259:         $authorsEngine = new DbEditors();
        !           260:         return $authorsEngine->getAllHtml();
        !           261:     }
        !           262:   }
        !           263: 
        !           264: function chgk_db_search_box_submit($form, &$form_state) {
        !           265:   $form_id = $form['form_id']['#value'];
        !           266:   $form_state['redirect'] = 'search/chgk_db/'. trim($form_state['values'][$form_id]);
        !           267: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>