PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/output_modules/publication/navbars.inc.php

https://github.com/adamfranco/segue-1.x
PHP | 130 lines | 95 code | 16 blank | 19 comment | 35 complexity | 39b1368fcf1c4d2b59f8eb2ff17170d0 MD5 | raw file
  1. <? /* $Id$ */
  2. //if ($action == 'viewsite') $topnav_extra = ($thisSite->hasPermission("add"))?" <a href='$PHP_SELF?$sid&".$envvars."&amp;action=add_section&amp;comingFrom=viewsite' class='".(($topsections)?"btnlink":"small")."' title='Add a new Section to this site. A section can hold one or many pages of content. You can also add a Link here instead of a Section.'>+ add section</a>":"";
  3. $isediting = 0;
  4. if ($action == 'viewsite') $isediting=1;
  5. // build topnav items
  6. $_ids = array_keys($thisSite->sections);
  7. /* print_r($_ids); */
  8. /* print "hello?"; */
  9. $link = "$PHP_SELF?$sid&amp;site=$site&amp;action=$action&amp;supplement=listissues";
  10. add_link(topnav,"ISSUES",$link,$extra,'',$target);
  11. add_link(topnav2,"ISSUES",$link,$extra,'',$target);
  12. if (count($_ids)) {
  13. $s = $_ids[0];$int = &$thisSite->sections;
  14. $l = $_ids[count($_ids)-1];
  15. if ($section && ($thisSection->getField("title")!="TOP" || ($action=='viewsite' && $_SESSION[atype] == 'admin'))) $last=&$int[$section];
  16. else $last = &$int[$l];
  17. $first = &$int[$s];
  18. /* print_r($so->pages); */
  19. foreach ($first->pages as $p=>$o) {
  20. /* print_r($o); */
  21. $link = "$PHP_SELF?$sid&amp;site=$site&amp;section=$section&amp;page=$p&amp;action=$action";
  22. add_link(topnav,$o->getField("title"),$link,$extra,'',$target);
  23. add_link(topnav2,$o->getField("title"),$link,$extra,'',$target);
  24. }
  25. add_link(leftnav,"<span class='smaller'><i>".strtoupper($last->getField("title"))."</i></span>");
  26. $pdfname = createPdfName($last->getField("title"));
  27. $filename = "$uploaddir/".$thisSite->name."/$pdfname";
  28. $fileurl = "$uploadurl/".$thisSite->name."/$pdfname";
  29. if (file_exists($filename)) {
  30. $putonlast = "<br /><div align='center' class='topmargin5 smaller'>".pdflink($filename,$fileurl)."</div>";
  31. }
  32. $i=0;$total = count($last->pages);
  33. foreach ($last->pages as $p=>$o) {
  34. $link = "$PHP_SELF?$sid&amp;site=$site&amp;section=$section&amp;page=$p&amp;action=$action";
  35. $extra = $list = '';
  36. if (($author = $o->getField("url")) && $author != "http://") $extra .= "<div class='leftmargin small' align='left'>by $author</div>";
  37. if ($isediting) {
  38. $list .= ($last->hasPermission("edit"))?"<a href='$PHP_SELF?$sid&amp;action=edit_page&amp;site=$site&amp;section=$section&amp;page=$p&amp;edit_page=$p&amp;comingFrom=$action'>edit</a>\n":"";
  39. $list .= ($last->hasPermission("delete"))?"<a href='$PHP_SELF?$sid&amp;action=delete_page&amp;site=$site&amp;section=$section&amp;page=$p&amp;delete_page=$p&amp;comingFrom=$action'>del</a>\n":"";
  40. if ($list != '') $extra .= "<div class='small' align='right'>".$list."</div>";
  41. }
  42. if ($i == $total-1) $extra .= $putonlast;
  43. add_link(leftnav,$o->getField("title"),$link,$extra,$p,$target);
  44. $i++;
  45. }
  46. add_link(leftnav);
  47. // add_link(leftnav2);
  48. }
  49. $i=0;
  50. $total=count($thisSite->sections);
  51. if ($thisSite->sections) {
  52. add_link(leftnav2,"<span class='smaller'>ISSUES</span>");
  53. foreach (array_reverse($thisSite->sections,TRUE) as $s=>$o) {
  54. if ($o->canview() || $o->hasPermissionDown("add or edit or delete")) {
  55. if ($i!=$total-1 || ($action=='viewsite' && $_SESSION[atype]=='admin')) {
  56. if ($o->getField("type") == 'section') $link = "$PHP_SELF?$sid&amp;site=$site&amp;section=$s&amp;action=$action&amp;supplement=listarticles";
  57. if ($o->getField("type") == 'url') { $link = $o->getField("url"); $target="_self";}
  58. $extra = '';
  59. $pdfname = $filename=$fileurl = '';
  60. $pdfname = createPdfName($o->getField("title"));
  61. $filename = "$uploaddir/".$thisSite->name."/$pdfname";
  62. $fileurl = "$uploadurl/".$thisSite->name."/$pdfname";
  63. if (file_exists($filename)) {
  64. $extra .= "<div align='center' class='leftmargin smaller'>".pdflink($filename,$fileurl,2)."</div>";
  65. }
  66. if ($isediting) {
  67. $extra .= ($thisSite->hasPermission("edit"))?"\n<a href='$PHP_SELF?$sid&amp;site=$site&amp;section=$s&amp;action=edit_section&amp;edit_section=$s&amp;comingFrom=viewsite' class='small' title='Edit the title and properties of this section'>edit</a>":"";
  68. $extra .= ($thisSite->hasPermission("delete"))?"\n<a href='javascript:doconfirm(\"Are absolutely sure you want to PERMANENTLY DELETE this section, including anything that may be held within it?? (you better be SURE!)\",\"$PHP_SELF?$sid&".$envvars."&action=delete_section&delete_section=$s\")' class='small' title='Delete this section'>del</a>":"";
  69. }
  70. add_link(leftnav2,$o->getField("title"),$link,$extra,$s,$target);
  71. }
  72. $i++;
  73. }
  74. }
  75. }
  76. if ($isediting) {
  77. $leftnav_extra = ($thisSite->hasPermission("add"))?" <a href='$PHP_SELF?$sid&".$envvars."&amp;action=add_section&amp;comingFrom=viewsite' class='small' title='Add a new Section to this site. A section can hold one or many pages of content. You can also add a Link here instead of a Section.'>+ add issue</a>":"";
  78. }
  79. /******************************************************************************
  80. * some functions from the old tko site.
  81. ******************************************************************************/
  82. function filesizestr($filename) {
  83. if (file_exists($filename)) $file_size = filesize($filename);
  84. else return "no file";
  85. /* $bytes = array("KB","MB","GB","TB");
  86. $units = 'Bytes';
  87. foreach ($bytes as $unit) {
  88. if ($size > 1024) {
  89. $size /= 1024;
  90. $units = $unit;
  91. } else end;
  92. }
  93. return sprintf("%.02f",$size)." $units";*/
  94. $j = 0;
  95. $ext = array("B","KB","MB","GB","TB");
  96. while ($file_size >= pow(1024,$j)) ++$j;
  97. $file_size = round($file_size / pow(1024,$j-1) * 100) / 100;
  98. if ($j <= 2) $file_size = round($file_size);
  99. $file_size .= $ext[$j-1];
  100. return $file_size;
  101. }
  102. function pdflink($filename,$fileurl,$sm=0) {
  103. $size = filesizestr($filename);
  104. return "<a href='$fileurl'>".(($sm!=2)?"<img src='images/pdficon".(($sm)?"_sm":"").".gif' align='absmiddle' border='0' alt='Download PDF' />":"") . (($sm==1)?" ":(($sm==2)?"":"<br />") . "Download PDF ")."</a>($size)";
  105. }
  106. function createPdfName($title) {
  107. $parts = explode(" - ",$title);
  108. $title = $parts[1];
  109. $title = str_replace("- ","",$title);
  110. $title = str_replace(" #","-",$title);
  111. $title = ereg_replace("([',])","",$title);
  112. $title = str_replace(" ","_",$title);
  113. return "TKO_$title.pdf";
  114. }