dokeos-metadata
[ class tree: dokeos-metadata ] [ index: dokeos-metadata ] [ all elements ]

Source for file importlinks.php

Documentation is available at importlinks.php

  1. <?php /*                                <!-- Dokeos metadata/importlinks.php -->
  2.                                                              <!-- 2006/12/15 -->
  3.  
  4. <!-- Copyright (C) 2006 rene.haentjens@UGent.be -  see metadata/md_funcs.php -->
  5.  
  6. */
  7.  
  8. /**
  9. ============================================================================== 
  10. *    Dokeos Metadata: create table entries for a category of Link-type items
  11. *
  12. *    @package dokeos.metadata
  13. ============================================================================== 
  14. */
  15.  
  16.  
  17. // PRELIMS -------------------------------------------------------------------->
  18.  
  19. $getpostvars array('lcn''slo')require('md_funcs.php');
  20.  
  21. define('EID_TYPE''Link');
  22. define('OF_EID_TYPE'"eid LIKE '" EID_TYPE ".%'");
  23.  
  24. require('md_' strtolower(EID_TYPE'.php');
  25.  
  26. // name of the language file that needs to be included 
  27. $language_file 'md_' strtolower(EID_TYPE);
  28. include('../inc/global.inc.php');
  29. $nameTools get_lang('Tool');
  30.  
  31. ($nameTools && get_lang('Sorry')) or give_up
  32.     'Language file ' $language_file " doesn't define 'Tool' and 'Sorry'");
  33.  
  34. $_course api_get_course_info()isset($_courseor give_up(get_lang('Sorry'));
  35.  
  36. $is_allowed_to_edit = isset($_user['user_id']&& $is_courseMember && is_allowed_to_edit();
  37. if (!$is_allowed_to_editgive_up(get_lang('Denied'));
  38.  
  39. $mdStore new mdstore($is_allowed_to_edit);  // create table if needed
  40.  
  41. require(api_get_path(LIBRARY_PATH'xmd.lib.php');
  42. require(api_get_path(LIBRARY_PATH'xht.lib.php');
  43.  
  44. require('md_phpdig.php');
  45.  
  46. $mdObj new mdobject($_course0);
  47. $mdCat $mdObj->mdo_dcmap_v['Coverage'];
  48. $mdUrl 'metadata/lom/technical/location[1]';
  49.  
  50. $mdObj->mdo_add_breadcrump_nav();  // see 'md_' . EID_TYPE . '.php'
  51.  
  52. $htmldecode array_flip(get_html_translation_table(HTML_SPECIALCHARS));
  53.  
  54.  
  55. function check_andor_get($row$get ''$check ''$tobe '')
  56. {
  57.     global $mdCat$htmldecode;
  58.  
  59.     if (!$check && !$getreturn FALSE;
  60.  
  61.     $regs array()// for use with ereg()
  62.  
  63.     if ($get == $mdCat && !$check)  // cheat to be quicker
  64.         if (ereg('<coverage>[^<]*<string language="..">([^<]+)<\/string>'
  65.             $row['mdxmltext']$regs)) return strtr($regs[1]$htmldecode);
  66.  
  67.     if ($check == $mdCat && !$get)  // cheat to be quicker
  68.         if (ereg('<coverage>[^<]*<string language="..">([^<]+)<\/string>'
  69.             $row['mdxmltext']$regs))
  70.                 return (strtr($regs[1]$htmldecode== $tobe);
  71.  
  72.     $xmlDoc new xmddoc(explode("\n"$row['mdxmltext']));
  73.     if ($xmlDoc->errorreturn FALSE;
  74.  
  75.     if (!$checkreturn $xmlDoc->xmd_value($get);
  76.  
  77.     if ($xmlDoc->xmd_value($check== $tobe)
  78.         return $get $xmlDoc->xmd_value($getTRUE;
  79.  
  80.     return FALSE;
  81. }
  82.  
  83.  
  84. function get_cat($catname)
  85. {
  86.     global $_course$cateq "category_title='"addslashes($catname"'";
  87.     
  88.     $linkcat_table Database::get_course_table(TABLE_LINK_CATEGORY);
  89.     $result api_sql_query("SELECT id FROM $linkcat_table WHERE $cateq__FILE____LINE__);
  90.     
  91.     if (mysql_num_rows($result>= && ($row mysql_fetch_array($result)))
  92.         return $row['id'];  // several categories with same name: take first
  93.     
  94.     return FALSE;
  95. }    
  96.  
  97.  
  98. // SET CURRENT LINKS CATEGORY - HEADER ---------------------------------------->
  99.  
  100. unset($lci);  // category-id
  101.  
  102. if (isset($lcn))  // category_title
  103. {
  104.     $lcn substr(ereg_replace("[^\x20-\x7E\xA1-\xFF]"""$lcn)0255);
  105.     
  106.     $uceids array()$mceids array();
  107.     
  108.     $result $mdStore->mds_get_many('eid,mdxmltext'OF_EID_TYPE);
  109.     
  110.     while ($row mysql_fetch_array($result))
  111.         if (check_andor_get($row''$mdCat$lcn)) $uceids[$row['eid'];
  112.  
  113.     if (($lci get_cat($lcn)) !== FALSE)
  114.     {
  115.         $link_table Database::get_course_table(TABLE_LINK);
  116.         $result api_sql_query("SELECT id FROM $link_table WHERE category_id=$lci__FILE____LINE__);
  117.         
  118.         while ($row mysql_fetch_array($result))
  119.         {
  120.             $lceids[$id = (int) $row['id']] ($eid EID_TYPE '.' $id);
  121.             
  122.             if (in_array($eid$uceids)) $mceids[$eid;
  123.         }
  124.         
  125.         $hdrInfo ' ' get_lang('WorkOn'' ' htmlspecialchars($lcn
  126.             ', LC-id=&nbsp;' htmlspecialchars($lci);
  127.     }
  128.     elseif ($lcn)
  129.     {
  130.         $hdrInfo ' (' htmlspecialchars($lcn
  131.             ': ' get_lang('NotInDB'')';
  132.     }
  133.     else
  134.         unset($lcn);
  135.  
  136.     $uceids array_diff($uceids$mceids);  // old entries with no link
  137.     
  138.     if (count($lceids&& count($uceids))
  139.     {
  140.         $mdStore->mds_delete_many($uceids)$ufos mysql_affected_rows();
  141.     }
  142.  
  143.     $interbreadcrumb[]array(
  144.         'url' => api_get_self('?lcn=' urlencode($lcn)
  145.         'name'=> get_lang('Continue'' ' htmlspecialchars($lcn));
  146. }
  147.  
  148. $htmlHeadXtra['
  149. <link rel="stylesheet" type="text/css" href="md_styles.css">
  150. <script type="text/javascript" src="md_script.js"></script>
  151. ';
  152. Display::display_header($nameTools);
  153.  
  154. // OPERATIONS ----------------------------------------------------------------->
  155.  
  156. if ($ufosecho '<h3>'$ufos' 'get_lang('RemainingFor')' '
  157.         htmlspecialchars($lcn)'</h3>'"\n";
  158.  
  159. if (isset($slo)) echo '<h3>'$slo'</h3>'"\n";  // selected links op
  160.  
  161. if (isset($slo))
  162. if ($slo == get_lang('Create'&& count($lceids))
  163. {
  164.     foreach ($lceids as $id => $eid)
  165.     {
  166.         $mdObj new mdobject($_course$id)$xht $mdObj->mdo_define_htt();
  167.         $mdStore->mds_put($eid$mdt $mdObj->mdo_generate_default_xml_metadata()
  168.             'mdxmltext''?');
  169.         $xht->xht_xmldoc new xmddoc(explode("\n"$mdt));
  170.         $mdStore->mds_put($eid$xht->xht_fill_template('INDEXABLETEXT')
  171.             'indexabletext');
  172.         echo '<span class="lbs" onClick="'"makeWindow('index.php?eid="
  173.             urlencode($eid)"', '', '')\">"htmlspecialchars($eid)'</span> ';
  174.     }
  175.     echo '<br>';
  176. }
  177. elseif ($slo == get_lang('Remove'&& count($lceids))
  178. {
  179.     $mdStore->mds_delete_many($mceids)$aff mysql_affected_rows();
  180.     
  181.     echo $aff' MDEs/ 'count($lceids)' 'get_lang('MdCallingTool')
  182.         '<br><br><b>'get_lang('AllRemovedFor')
  183.         ' 'htmlspecialchars($lcn)'</b><br>';
  184. }
  185. elseif ($slo == get_lang('Remove'&& count($mceids))  // obsolete category
  186. {
  187.     $mdStore->mds_delete_many($mceids);
  188.     
  189.     echo get_lang('AllRemovedFor')' 'htmlspecialchars($lcn)'<br>';
  190. }
  191. elseif ($slo == get_lang('Index'&& file_exists($phpDigIncCn&& count($mceids))
  192. {
  193.     $result $mdStore->mds_get_many('eid,mdxmltext,indexabletext'
  194.         OF_EID_TYPE " AND eid IN ('" 
  195.         implode("','"array_map('addslashes'$mceids)) "')");
  196.     
  197.     while ($row mysql_fetch_array($result))  // load indexabletexts in memory
  198.         $idt[check_andor_get($row$mdUrl)$row['indexabletext'];
  199.     
  200.     require($phpDigIncCn);  // switch to PhpDig DB
  201.     
  202.     foreach ($idt as $url => $text)
  203.     {
  204.         $pu parse_url($url);
  205.         if (!isset($pu['scheme'])) $pu['scheme'"http";
  206.         
  207.         if (isset($pu['host']))
  208.         {
  209.             $url $pu['scheme'"://" $pu['host'"/"$file '';
  210.             
  211.             if (($path $pu['path']))
  212.             if (substr($path-1== '/'$path substr($path1);
  213.             else
  214.             {
  215.                 $pi pathinfo($path)$path $pi['dirname'];
  216.                 if ($path{0== '\\'$path substr($path1);
  217.                 if ($path{0== '/')  $path substr($path1'/';
  218.                 
  219.                 $file $pi['basename'];
  220.             }
  221.             
  222.             $file .= ($pu['query''?'.$pu['query'''
  223.                     ($pu['fragment''#'.$pu['fragment''');
  224.             
  225.             
  226.             if ($site_id remove_engine_entries($url$path$file))
  227.             {
  228.                 echo '<table>'"\n";
  229.                 index_words($site_id$path$file
  230.                     get_first_words($text$url $path$file)
  231.                     get_keywords($text));
  232.                 echo '</table>'"\n";
  233.             }
  234.             else
  235.             {
  236.                 echo '<table>'"\n";
  237.                 echo '<tr><td>'htmlspecialchars($url)
  238.                     '</td><td>'htmlspecialchars($path)
  239.                     '</td><td>'htmlspecialchars($file)'</td></tr>';
  240.                 echo '</table>'"\n";
  241.             }
  242.         }
  243.         elseif (isset($pu['scheme']&& $pu['scheme'== 'mailto' && isset($pu['path']))
  244.         {
  245.             if ($site_id remove_engine_entries($url 'mailto:' $pu['path']''))
  246.             {
  247.                 echo '<table>'"\n";
  248.                 index_words($site_id''''
  249.                     get_first_words($text$url'')
  250.                     get_keywords($text));
  251.                 echo '</table>'"\n";
  252.             }
  253.             else
  254.             {
  255.                 echo '<table>'"\n";
  256.                 echo '<tr><td>'htmlspecialchars($url)
  257.                     '</td><td>'htmlspecialchars($path)
  258.                     '</td><td>'htmlspecialchars($file)'</td></tr>';
  259.                 echo '</table>'"\n";
  260.             }
  261.         }
  262.     }
  263.     
  264.     if(isset($db))
  265.     {
  266.         mysql_select_db($_configuration['main_database']$db);  // back to Dokeos
  267.     }
  268. }
  269. elseif ($slo == get_lang('Index'))
  270. {
  271.     echo 'Problem! PhpDig connect.php has gone ...';
  272. }
  273.  
  274.  
  275. // STATISTICS ----------------------------------------------------------------->
  276.  
  277. echo '<h3>'get_lang('Statistics')'</h3>'"\n";
  278.  
  279. $result $mdStore->mds_get_many('eid,mdxmltext'OF_EID_TYPE);
  280. echo get_lang('TotalMDEs')mysql_num_rows($result)"\n";
  281.  
  282. while ($row mysql_fetch_array($result))
  283. {
  284.     $cat check_andor_get($row$mdCat);
  285.     $perCat[$cat($pc $perCat[$cat]$pc 1;
  286. }
  287.  
  288. if (count($perCat))
  289. {
  290.     echo '<table>'"\n";
  291.     foreach ($perCat as $cat => $number)
  292.     {
  293.         echo '<tr><td>'$cat == $lcn '' '('htmlspecialchars($cat)
  294.             $cat == $lcn '' ')'':</td><td align="right">'
  295.             $number'</td></tr>'"\n";
  296.     }
  297.     echo '</table>'"\n";
  298. }
  299.  
  300. if (isset($lci))
  301. {
  302.     echo '<br><br>'htmlspecialchars($lcn)' 'get_lang('MdCallingTool')
  303.         ': 'count($lceids)'<br>'"\n";
  304. }
  305.  
  306.  
  307.  
  308. // SELECT & FOOTER ------------------------------------------------------------>
  309.  
  310. echo '<h3>'$nameTools$hdrInfo'</h3>'"\n";
  311.  
  312. echo '<form action="' .api_get_self()'?lcn=' urlencode($lcn
  313.     '" method="post">'"\n"
  314.  
  315. if (count($lceids)) echo 
  316.     '<input type="submit" name="slo" value="'get_lang('Create')'">'"\n";
  317. if ($perCat[$lcn]echo 
  318.     '<input type="submit" name="slo" value="'get_lang('Remove')'">'"\n";
  319. if ($perCat[$lcn&& file_exists($phpDigIncCn)) echo 
  320.     '<input type="submit" name="slo" value="'get_lang('Index')'">'"\n";
  321.  
  322. echo '</form>'"\n";
  323.  
  324. if (count($perCat)) foreach ($perCat as $cat => $number
  325.     $perCat[$cat'(' htmlspecialchars($cat')';
  326.  
  327. $result api_sql_query("SELECT category_title FROM $linkcat_table"__FILE____LINE__);
  328.  
  329. while ($row mysql_fetch_array($result))
  330. {
  331.     $cat $row['category_title']$hcat htmlspecialchars($cat);
  332.     if ($perCat[$cat== $hcat$dups[$cat;
  333.     else $perCat[$cat$hcat;
  334. }
  335.  
  336. if (count($dups))
  337. {
  338.     $warning get_lang('WarningDups');;
  339.     
  340.     foreach ($dups as $catunset($perCat[$cat]);
  341. }
  342.  
  343. echo '<h3>'get_lang('OrElse')$warning'</h3>'"\n",  // select new target
  344.     '<table><tr><td align="right" class="alternativeBgDark">'"\n"
  345.     '<form action="'.api_get_self().'" method="post">'"\n"
  346.     get_lang('SLC')' :'"\n"'<select name="lcn">'"\n",
  347.     '<option value=""></option>'"\n";
  348.     
  349.     foreach ($perCat as $cat => $textecho '<option value="' 
  350.         htmlspecialchars($cat'"' 
  351.         ($cat == $lcn ' selected' '''>' $text '</option>'"\n";
  352.  
  353. echo '</select><input type="submit" value="'get_lang('Ok')'">'"\n"
  354.     '</form>'"\n"'</td></tr></table>'"\n";
  355.  
  356. ?>

Documentation generated on Thu, 12 Jun 2008 13:47:36 -0500 by phpDocumentor 1.4.1