/** * Makes sure we have the requested number of bits in the working buffer * * @access private * @param int $cnt The number of bits needed */ function fetch($cnt) { if ($this->pos < $this->ofs * 8 || $this->pos + $cnt > $this->ofs * 8 + strlen($this->bits)) { $this->bits = ''; $this->ofs = FLOOR($this->pos / 8); for ($i = $this->ofs; $i <= $this->ofs + CEIL($cnt / 8); $i++) { $this->bits .= str_pad(decbin(ord($this->data[$i])), 8, '0', STR_PAD_LEFT); } } }
/** * Makes sure we have the requested number of bits in the working buffer * * @access private * @param int $cnt The number of bits needed */ private function fetch($cnt) { // Either we already have the needed bits in the buffer or we rebuild it if ($this->pos < $this->ofs * 8 || $this->pos + $cnt > $this->ofs * 8 + strlen($this->bits)) { $this->bits = ''; $this->ofs = FLOOR($this->pos / 8); for ($i = $this->ofs; $i <= $this->ofs + CEIL($cnt / 8); $i++) { $this->bits .= str_pad(decbin(ord($this->data[$i])), 8, '0', STR_PAD_LEFT); } } }
function WriteFixedPosHTML($html='',$x, $y, $w, $h, $overflow='visible', $bounding=array()) { // $overflow can be 'hidden', 'visible' or 'auto' - 'auto' causes autofit to size // Annotations disabled - enabled in mPDF 5.0 // Links do work // Will always go on current page (or start Page 1 if required) // Probably INCOMPATIBLE WITH keep with table, columns etc. // Called externally or interally via <div style="position: [fixed|absolute]"> // When used internally, $x $y $w $h and $overflow are all overridden by $bounding $overflow = strtolower($overflow); if($this->state==0) { $this->AddPage($this->CurOrientation); } $save_y = $this->y; $save_x = $this->x; $this->fullImageHeight = $this->h; $save_cols = false; /*-- COLUMNS --*/ if ($this->ColActive) { $save_cols = true; $save_nbcol = $this->NbCol; // other values of gap and vAlign will not change by setting Columns off $this->SetColumns(0); } /*-- END COLUMNS --*/ $save_annots = $this->title2annots; // *ANNOTATIONS* $this->writingHTMLheader = true; // a FIX to stop pagebreaks etc. $this->writingHTMLfooter = true; $this->InFooter = true; // suppresses autopagebreaks $save_bgs = $this->pageBackgrounds; $checkinnerhtml = preg_replace('/\s/','',$html); if ($w > $this->w) { $x = 0; $w = $this->w; } if ($h > $this->h) { $y = 0; $h = $this->h; } if ($x > $this->w) { $x = $this->w - $w; } if ($y > $this->h) { $y = $this->h - $h; } if (!empty($bounding)) { // $cont_ containing block = full physical page (position: absolute) or page inside margins (position: fixed) // $bbox_ Bounding box is the <div> which is positioned absolutely/fixed // top/left/right/bottom/width/height/background*/border*/padding*/margin* are taken from bounding // font*[family/size/style/weight]/line-height/text*[align/decoration/transform/indent]/color are transferred to $inner // as an enclosing <div> (after having checked ID/CLASS) // $x, $y, $w, $h are inside of $bbox_ = containing box for $inner_ // $inner_ InnerHTML is the contents of that block to be output $tag = $bounding[0]; $attr = $bounding[1]; $orig_x0 = $bounding[2]; $orig_y0 = $bounding[3]; // As in WriteHTML() initialising $this->blklvl = 0; $this->lastblocklevelchange = 0; $this->blk = array(); $this->initialiseBlock($this->blk[0]); $this->blk[0]['width'] =& $this->pgwidth; $this->blk[0]['inner_width'] =& $this->pgwidth; $this->blk[0]['blockContext'] = $this->blockContext; $properties = $this->cssmgr->MergeCSS('BLOCK','BODY',''); $this->setCSS($properties,'','BODY'); $this->blklvl = 1; $this->initialiseBlock($this->blk[1]); $this->blk[1]['tag'] = $tag; $this->blk[1]['attr'] = $attr; $this->Reset(); $p = $this->cssmgr->MergeCSS('BLOCK',$tag,$attr); if (isset($p['ROTATE']) && ($p['ROTATE']==90 || $p['ROTATE']==-90)) { $rotate = $p['ROTATE']; } else { $rotate = 0; } if (isset($p['OVERFLOW'])) { $overflow = strtolower($p['OVERFLOW']); } if (strtolower($p['POSITION']) == 'fixed') { $cont_w = $this->pgwidth; // $this->blk[0]['inner_width']; $cont_h = $this->h - $this->tMargin - $this->bMargin; $cont_x = $this->lMargin; $cont_y = $this->tMargin; } else { $cont_w = $this->w; // ABSOLUTE; $cont_h = $this->h; $cont_x = 0; $cont_y = 0; } // Pass on in-line properties to the innerhtml $css = ''; if (isset($p['TEXT-ALIGN'])) { $css .= 'text-align: '.strtolower($p['TEXT-ALIGN']).'; '; } if (isset($p['TEXT-TRANSFORM'])) { $css .= 'text-transform: '.strtolower($p['TEXT-TRANSFORM']).'; '; } if (isset($p['TEXT-INDENT'])) { $css .= 'text-indent: '.strtolower($p['TEXT-INDENT']).'; '; } if (isset($p['TEXT-DECORATION'])) { $css .= 'text-decoration: '.strtolower($p['TEXT-DECORATION']).'; '; } if (isset($p['FONT-FAMILY'])) { $css .= 'font-family: '.strtolower($p['FONT-FAMILY']).'; '; } if (isset($p['FONT-STYLE'])) { $css .= 'font-style: '.strtolower($p['FONT-STYLE']).'; '; } if (isset($p['FONT-WEIGHT'])) { $css .= 'font-weight: '.strtolower($p['FONT-WEIGHT']).'; '; } if (isset($p['FONT-SIZE'])) { $css .= 'font-size: '.strtolower($p['FONT-SIZE']).'; '; } if (isset($p['LINE-HEIGHT'])) { $css .= 'line-height: '.strtolower($p['LINE-HEIGHT']).'; '; } if (isset($p['TEXT-SHADOW'])) { $css .= 'text-shadow: '.strtolower($p['TEXT-SHADOW']).'; '; } if (isset($p['LETTER-SPACING'])) { $css .= 'letter-spacing: '.strtolower($p['LETTER-SPACING']).'; '; } if (isset($p['FONT-VARIANT'])) { $css .= 'font-variant: '.strtolower($p['FONT-VARIANT']).'; '; } if (isset($p['COLOR'])) { $css .= 'color: '.strtolower($p['COLOR']).'; '; } if (isset($p['Z-INDEX'])) { $css .= 'z-index: '.$p['Z-INDEX'].'; '; } // mPDF 5.6.01 if ($css) { $html = '<div style="'.$css.'">'.$html.'</div>'; } // Copy over (only) the properties to set for border and background $pb = array(); $pb['MARGIN-TOP'] = $p['MARGIN-TOP']; $pb['MARGIN-RIGHT'] = $p['MARGIN-RIGHT']; $pb['MARGIN-BOTTOM'] = $p['MARGIN-BOTTOM']; $pb['MARGIN-LEFT'] = $p['MARGIN-LEFT']; $pb['PADDING-TOP'] = $p['PADDING-TOP']; $pb['PADDING-RIGHT'] = $p['PADDING-RIGHT']; $pb['PADDING-BOTTOM'] = $p['PADDING-BOTTOM']; $pb['PADDING-LEFT'] = $p['PADDING-LEFT']; $pb['BORDER-TOP'] = $p['BORDER-TOP']; $pb['BORDER-RIGHT'] = $p['BORDER-RIGHT']; $pb['BORDER-BOTTOM'] = $p['BORDER-BOTTOM']; $pb['BORDER-LEFT'] = $p['BORDER-LEFT']; $pb['BORDER-TOP-LEFT-RADIUS-H'] = $p['BORDER-TOP-LEFT-RADIUS-H']; $pb['BORDER-TOP-LEFT-RADIUS-V'] = $p['BORDER-TOP-LEFT-RADIUS-V']; $pb['BORDER-TOP-RIGHT-RADIUS-H'] = $p['BORDER-TOP-RIGHT-RADIUS-H']; $pb['BORDER-TOP-RIGHT-RADIUS-V'] = $p['BORDER-TOP-RIGHT-RADIUS-V']; $pb['BORDER-BOTTOM-LEFT-RADIUS-H'] = $p['BORDER-BOTTOM-LEFT-RADIUS-H']; $pb['BORDER-BOTTOM-LEFT-RADIUS-V'] = $p['BORDER-BOTTOM-LEFT-RADIUS-V']; $pb['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-H']; $pb['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $p['BORDER-BOTTOM-RIGHT-RADIUS-V']; if (isset($p['BACKGROUND-COLOR'])) { $pb['BACKGROUND-COLOR'] = $p['BACKGROUND-COLOR']; } if (isset($p['BOX-SHADOW'])) { $pb['BOX-SHADOW'] = $p['BOX-SHADOW']; } /*-- BACKGROUNDS --*/ if (isset($p['BACKGROUND-IMAGE'])) { $pb['BACKGROUND-IMAGE'] = $p['BACKGROUND-IMAGE']; } if (isset($p['BACKGROUND-IMAGE-RESIZE'])) { $pb['BACKGROUND-IMAGE-RESIZE'] = $p['BACKGROUND-IMAGE-RESIZE']; } if (isset($p['BACKGROUND-IMAGE-OPACITY'])) { $pb['BACKGROUND-IMAGE-OPACITY'] = $p['BACKGROUND-IMAGE-OPACITY']; } if (isset($p['BACKGROUND-REPEAT'])) { $pb['BACKGROUND-REPEAT'] = $p['BACKGROUND-REPEAT']; } if (isset($p['BACKGROUND-POSITION'])) { $pb['BACKGROUND-POSITION'] = $p['BACKGROUND-POSITION']; } if (isset($p['BACKGROUND-GRADIENT'])) { $pb['BACKGROUND-GRADIENT'] = $p['BACKGROUND-GRADIENT']; } if (isset($p['BACKGROUND-SIZE'])) { $pb['BACKGROUND-SIZE'] = $p['BACKGROUND-SIZE']; } // mPDF 5.6.12 if (isset($p['BACKGROUND-ORIGIN'])) { $pb['BACKGROUND-ORIGIN'] = $p['BACKGROUND-ORIGIN']; } // mPDF 5.6.12 if (isset($p['BACKGROUND-CLIP'])) { $pb['BACKGROUND-CLIP'] = $p['BACKGROUND-CLIP']; } // mPDF 5.6.12 /*-- END BACKGROUNDS --*/ $this->setCSS($pb,'BLOCK',$tag); //================================================================ $bbox_br = $this->blk[1]['border_right']['w']; $bbox_bl = $this->blk[1]['border_left']['w']; $bbox_bt = $this->blk[1]['border_top']['w']; $bbox_bb = $this->blk[1]['border_bottom']['w']; $bbox_pr = $this->blk[1]['padding_right']; $bbox_pl = $this->blk[1]['padding_left']; $bbox_pt = $this->blk[1]['padding_top']; $bbox_pb = $this->blk[1]['padding_bottom']; $bbox_mr = $this->blk[1]['margin_right']; if (strtolower($p['MARGIN-RIGHT'])=='auto') { $bbox_mr = 'auto'; } $bbox_ml = $this->blk[1]['margin_left']; if (strtolower($p['MARGIN-LEFT'])=='auto') { $bbox_ml = 'auto'; } $bbox_mt = $this->blk[1]['margin_top']; if (strtolower($p['MARGIN-TOP'])=='auto') { $bbox_mt = 'auto'; } $bbox_mb = $this->blk[1]['margin_bottom']; if (strtolower($p['MARGIN-BOTTOM'])=='auto') { $bbox_mb = 'auto'; } if (isset($p['LEFT']) && strtolower($p['LEFT'])!='auto') { $bbox_left = $this->ConvertSize($p['LEFT'], $cont_w, $this->FontSize,false); } else { $bbox_left = 'auto'; } if (isset($p['TOP']) && strtolower($p['TOP'])!='auto') { $bbox_top = $this->ConvertSize($p['TOP'], $cont_h, $this->FontSize,false); } else { $bbox_top = 'auto'; } if (isset($p['RIGHT']) && strtolower($p['RIGHT'])!='auto') { $bbox_right = $this->ConvertSize($p['RIGHT'], $cont_w, $this->FontSize,false); } else { $bbox_right = 'auto'; } if (isset($p['BOTTOM']) && strtolower($p['BOTTOM'])!='auto') { $bbox_bottom = $this->ConvertSize($p['BOTTOM'], $cont_h, $this->FontSize,false); } else { $bbox_bottom = 'auto'; } if (isset($p['WIDTH']) && strtolower($p['WIDTH'])!='auto') { $inner_w = $this->ConvertSize($p['WIDTH'], $cont_w, $this->FontSize,false); } else { $inner_w = 'auto'; } if (isset($p['HEIGHT']) && strtolower($p['HEIGHT'])!='auto') { $inner_h = $this->ConvertSize($p['HEIGHT'], $cont_h, $this->FontSize,false); } else { $inner_h = 'auto'; } // If bottom or right pos are set and not left / top - save this to adjust rotated block later if ($rotate) { if ($bbox_left === 'auto' && $bbox_right !== 'auto') { $rot_rpos = $bbox_right; } else { $rot_rpos = false; } if ($bbox_top === 'auto' && $bbox_bottom !== 'auto') { $rot_bpos = $bbox_bottom; } else { $rot_bpos = false; } } //================================================================ if ($checkinnerhtml=='' && $inner_h==='auto') { $inner_h = 0.0001; } if ($checkinnerhtml=='' && $inner_w==='auto') { $inner_w = 2*$this->GetCharWidth('W',false); } //================================================================ // Algorithm from CSS2.1 See http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-height // mPD 5.3.14 // Special case (not CSS) if all not specified, centre vertically on page if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto' && $bbox_mt==='auto' && $bbox_mb==='auto') { $bbox_top_orig = $bbox_top; if ($bbox_mt==='auto') { $bbox_mt = 0; } if ($bbox_mb==='auto') { $bbox_mb = 0; } $bbox_top = $orig_y0 - $bbox_mt - $cont_y; // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto' } // mPD 5.3.14 else if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom==='auto') { $bbox_top_orig = $bbox_top = $orig_y0 - $cont_y; if ($bbox_mt==='auto') { $bbox_mt = 0; } if ($bbox_mb==='auto') { $bbox_mb = 0; } // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto' } else if ($bbox_top!=='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') { if ($bbox_mt==='auto' && $bbox_mb==='auto') { $x = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom; $bbox_mt = $bbox_mb = ($x/2); } else if ($bbox_mt==='auto') { $bbox_mt = $cont_h - $bbox_top - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; } else if ($bbox_mb==='auto') { $bbox_mb = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_bottom; } else { $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt; } } else { if ($bbox_mt==='auto') { $bbox_mt = 0; } if ($bbox_mb==='auto') { $bbox_mb = 0; } if ($bbox_top==='auto' && $inner_h==='auto' && $bbox_bottom!=='auto') { // solve for $bbox_top when content_h known - $inner_h=='auto' && $bbox_top =='auto' } else if ($bbox_top==='auto' && $bbox_bottom==='auto' && $inner_h!=='auto') { $bbox_top = $orig_y0 - $bbox_mt - $cont_y; $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt; } else if ($inner_h==='auto' && $bbox_bottom==='auto' && $bbox_top!=='auto') { // solve for $bbox_bottom when content_h known - $inner_h=='auto' && $bbox_bottom=='auto' } else if ($bbox_top==='auto' && $inner_h!=='auto' && $bbox_bottom!=='auto') { $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom; } else if ($inner_h==='auto' && $bbox_top!=='auto' && $bbox_bottom!=='auto') { $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mt - $bbox_bottom; } else if ($bbox_bottom==='auto' && $bbox_top!=='auto' && $inner_h!=='auto') { $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mt; } } // THEN DO SAME FOR WIDTH // http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right==='auto') { if ($bbox_ml==='auto') { $bbox_ml = 0; } if ($bbox_mr==='auto') { $bbox_mr = 0; } // IF containing element RTL, should set $bbox_right $bbox_left = $orig_x0 - $bbox_ml - $cont_x; // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto' } else if ($bbox_left!=='auto' && $inner_w!=='auto' && $bbox_right!=='auto') { if ($bbox_ml==='auto' && $bbox_mr==='auto') { $x = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right; $bbox_ml = $bbox_mr = ($x/2); } else if ($bbox_ml==='auto') { $bbox_ml = $cont_w - $bbox_left - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right; } else if ($bbox_mr==='auto') { $bbox_mr = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_right; } else { $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml; } } else { if ($bbox_ml==='auto') { $bbox_ml = 0; } if ($bbox_mr==='auto') { $bbox_mr = 0; } if ($bbox_left==='auto' && $inner_w==='auto' && $bbox_right!=='auto') { // solve for $bbox_left when content_w known - $inner_w=='auto' && $bbox_left =='auto' } else if ($bbox_left==='auto' && $bbox_right==='auto' && $inner_w!=='auto') { // IF containing element RTL, should set $bbox_right $bbox_left = $orig_x0 - $bbox_ml - $cont_x; $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml; } else if ($inner_w==='auto' && $bbox_right==='auto' && $bbox_left!=='auto') { // solve for $bbox_right when content_w known - $inner_w=='auto' && $bbox_right=='auto' } else if ($bbox_left==='auto' && $inner_w!=='auto' && $bbox_right!=='auto') { $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right; } else if ($inner_w==='auto' && $bbox_left!=='auto' && $bbox_right!=='auto') { $inner_w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right; } else if ($bbox_right==='auto' && $bbox_left!=='auto' && $inner_w!=='auto') { $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml; } } //================================================================ //================================================================ /*-- BACKGROUNDS --*/ if (isset($pb['BACKGROUND-IMAGE']) && $pb['BACKGROUND-IMAGE']) { $ret = $this->SetBackground($pb, $this->blk[1]['inner_width']); if ($ret) { $this->blk[1]['background-image'] = $ret; } } /*-- END BACKGROUNDS --*/ //================================================================ $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt; $h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl; $w = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $bbox_pr - $bbox_br - $bbox_mr - $bbox_right; // Set (temporary) values for x y w h to do first paint, if values are auto if ($inner_h==='auto' && $bbox_top==='auto') { $y = $cont_y + $bbox_mt + $bbox_bt + $bbox_pt; $h = $cont_h - ($bbox_bottom + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb); } else if ($inner_h==='auto' && $bbox_bottom==='auto') { $y = $cont_y + $bbox_top + $bbox_mt + $bbox_bt + $bbox_pt; $h = $cont_h - ($bbox_top + $bbox_mt + $bbox_mb + $bbox_bt + $bbox_bb + $bbox_pt + $bbox_pb); } if ($inner_w==='auto' && $bbox_left==='auto') { $x = $cont_x + $bbox_ml + $bbox_bl + $bbox_pl; $w = $cont_w - ($bbox_right + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr); } else if ($inner_w==='auto' && $bbox_right==='auto') { $x = $cont_x + $bbox_left + $bbox_ml + $bbox_bl + $bbox_pl; $w = $cont_w - ($bbox_left + $bbox_ml + $bbox_mr + $bbox_bl + $bbox_br + $bbox_pl + $bbox_pr); } $bbox_y = $cont_y + $bbox_top + $bbox_mt; $bbox_x = $cont_x + $bbox_left + $bbox_ml; $saved_block1 = $this->blk[1]; unset($p); unset($pb); //================================================================ if ($inner_w==='auto') { // do a first write $this->lMargin=$x; $this->rMargin=$this->w - $w - $x; // SET POSITION & FONT VALUES $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->pageoutput[$this->page]=array(); $this->x = $x; $this->y = $y; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->maxPosR = 0; $this->maxPosL = $this->w; // For RTL $this->WriteHTML($html , 4); $inner_w = $this->maxPosR - $this->lMargin; if ($bbox_right==='auto') { $bbox_right = $cont_w - $bbox_left - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml; } else if ($bbox_left==='auto') { $bbox_left = $cont_w - $bbox_ml - $bbox_bl - $bbox_pl - $inner_w - $bbox_pr - $bbox_br - $bbox_ml - $bbox_right; $bbox_x = $cont_x + $bbox_left + $bbox_ml ; $inner_x = $bbox_x + $bbox_bl + $bbox_pl; $x = $inner_x; } $w = $inner_w; $bbox_y = $cont_y + $bbox_top + $bbox_mt; $bbox_x = $cont_x + $bbox_left + $bbox_ml; } if ($inner_h==='auto') { // do a first write $this->lMargin=$x; $this->rMargin=$this->w - $w - $x; // SET POSITION & FONT VALUES $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->pageoutput[$this->page]=array(); $this->x = $x; $this->y = $y; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->WriteHTML($html , 4); $inner_h = $this->y - $y; if ($overflow!='hidden' && $overflow!='visible') { // constrained if (($this->y + $bbox_pb + $bbox_bb) > ($cont_y + $cont_h)) { $adj = ($this->y + $bbox_pb + $bbox_bb) - ($cont_y + $cont_h); $inner_h -= $adj; } } if ($bbox_bottom==='auto' && $bbox_top_orig==='auto') { $bbox_bottom = $bbox_top = ($cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb)/2; if ($overflow!='hidden' && $overflow!='visible') { // constrained if ($bbox_top < 0) { $bbox_top = 0; $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; } } $bbox_y = $cont_y + $bbox_top + $bbox_mt; $inner_y = $bbox_y + $bbox_bt + $bbox_pt; $y = $inner_y; } else if ($bbox_bottom==='auto') { $bbox_bottom = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb; } else if ($bbox_top==='auto') { $bbox_top = $cont_h - $bbox_mt - $bbox_bt - $bbox_pt - $inner_h - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; if ($overflow!='hidden' && $overflow!='visible') { // constrained if ($bbox_top < 0) { $bbox_top = 0; $inner_h = $cont_h - $bbox_top - $bbox_mt - $bbox_bt - $bbox_pt - $bbox_pb - $bbox_bb - $bbox_mb - $bbox_bottom; } } $bbox_y = $cont_y + $bbox_top + $bbox_mt; $inner_y = $bbox_y + $bbox_bt + $bbox_pt; $y = $inner_y; } $h = $inner_h; $bbox_y = $cont_y + $bbox_top + $bbox_mt; $bbox_x = $cont_x + $bbox_left + $bbox_ml; } $inner_w = $w; $inner_h = $h; } $this->lMargin=$x; $this->rMargin=$this->w - $w - $x; // SET POSITION & FONT VALUES $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->pageoutput[$this->page]=array(); $this->x = $x; $this->y = $y; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer $actual_h = $this->y - $y; $use_w = $w; $use_h = $h; $ratio = $actual_h / $use_w; if ($overflow!='hidden' && $overflow!='visible') { $target = $h/$w; if (($ratio / $target ) > 1) { $nl = CEIL($actual_h / $this->lineheight); $l = $use_w * $nl; $est_w = sqrt(($l * $this->lineheight) / $target) * 0.8; $use_w += ($est_w - $use_w) - ($w/100); } $bpcstart = ($ratio / $target); $bpcctr = 1; while(($ratio / $target ) > 1) { if ($this->progressBar) { $this->UpdateProgressBar(4,intval(100/($ratio/$target)),('Auto-sizing fixed-position block: '.$bpcctr++)); } // *PROGRESS-BAR* $this->x = $x; $this->y = $y; if (($ratio / $target) > 1.5 || ($ratio / $target) < 0.6) { $use_w += ($w/$this->incrementFPR1); } else if (($ratio / $target) > 1.2 || ($ratio / $target) < 0.85) { $use_w += ($w/$this->incrementFPR2); } else if (($ratio / $target) > 1.1 || ($ratio / $target) < 0.91) { $use_w += ($w/$this->incrementFPR3); } else { $use_w += ($w/$this->incrementFPR4); } $use_h = $use_w * $target ; $this->rMargin=$this->w - $use_w - $x; $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = array(); $this->WriteHTML($html , 4); // parameter 4 saves output to $this->headerbuffer $actual_h = $this->y - $y; $ratio = $actual_h / $use_w; } if ($this->progressBar) { $this->UpdateProgressBar(4,'100',' '); } // *PROGRESS-BAR* } $shrink_f = $w/$use_w; //================================================================ $this->pages[$this->page] .= '___BEFORE_BORDERS___'; $block_s = $this->PrintPageBackgrounds(); // Save to print later inside clipping path $this->pageBackgrounds = array(); //================================================================ if ($rotate) { $prerotw = $bbox_bl + $bbox_pl + $inner_w + $bbox_pr + $bbox_br; $preroth = $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb; $rot_start = " q\n"; if ($rotate == 90) { if ($rot_rpos !== false) { $adjw = $prerotw; } // width before rotation else { $adjw = $preroth; } // height before rotation if ($rot_bpos !== false) { $adjh = -$prerotw + $preroth; } else { $adjh = 0; } } else { if ($rot_rpos !== false) { $adjw = $prerotw - $preroth; } else { $adjw = 0; } if ($rot_bpos !== false) { $adjh = $preroth; } // height before rotation else { $adjh = $prerotw; } // width before rotation } $rot_start .= $this->transformTranslate($adjw, $adjh, true)."\n"; $rot_start .= $this->transformRotate($rotate, $bbox_x, $bbox_y, true)."\n"; $rot_end = " Q\n"; } else { $rot_start = ''; $rot_end = ''; } //================================================================ if (!empty($bounding)) { // WHEN HEIGHT // BOTTOM EDGE IS KNOWN and $this->y is set to the bottom // Re-instate saved $this->blk[1] $this->blk[1] = $saved_block1; // These are only needed when painting border/background $this->blk[1]['width'] = $bbox_w = $cont_w - $bbox_left - $bbox_ml - $bbox_mr - $bbox_right; $this->blk[1]['x0'] = $bbox_x; $this->blk[1]['y0'] = $bbox_y; $this->blk[1]['startpage'] = $this->page; $this->blk[1]['y1'] = $bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ; $this->_out($rot_start); // mPDF 5.0 $this->PaintDivBB('',0,1); // Prints borders and sets backgrounds in $this->pageBackgrounds $this->_out($rot_end); } $s = $this->PrintPageBackgrounds(); $s = $rot_start.$s.$rot_end; $this->pages[$this->page] = preg_replace('/___BEFORE_BORDERS___/', "\n".$s."\n", $this->pages[$this->page]); $this->pageBackgrounds = array(); $this->_out($rot_start); // Clipping Output if ($overflow=='hidden') { //Bounding rectangle to clip $clip_y1 = $this->y; if (!empty($bounding) && ($this->y + $bbox_pb + $bbox_bb) > ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb )) { $clip_y1 = ($bbox_y + $bbox_bt + $bbox_pt + $inner_h + $bbox_pb + $bbox_bb ) - ($bbox_pb + $bbox_bb); } //$op = 'W* n'; // Clipping $op = 'W n'; // Clipping alternative mode $this->_out("q"); $ch = $clip_y1 - $y; $this->_out(sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op)); if (!empty($block_s)) { $tmp = "q\n".sprintf('%.3F %.3F %.3F %.3F re %s',$x*_MPDFK,($this->h-$y)*_MPDFK,$w*_MPDFK,-$ch*_MPDFK,$op); $tmp .= "\n".$block_s."\nQ"; $block_s = $tmp ; } } if (!empty($block_s)) { if ($shrink_f != 1) { // i.e. autofit has resized the box $tmp = "q\n".$this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y, true); $tmp .= "\n".$block_s."\nQ"; $block_s = $tmp ; } $this->_out($block_s); } if ($shrink_f != 1) { // i.e. autofit has resized the box $this->StartTransform(); $this->transformScale(($shrink_f*100),($shrink_f*100), $x, $y); } $this->_out($this->headerbuffer); if ($shrink_f != 1) { // i.e. autofit has resized the box $this->StopTransform(); } if ($overflow=='hidden') { //End clipping $this->_out("Q"); } $this->_out($rot_end); // Page Links foreach($this->HTMLheaderPageLinks AS $lk) { if ($rotate) { $tmp = $lk[2]; // Switch h - w $lk[2] = $lk[3]; $lk[3] = $tmp; $lx1 = (($lk[0]/_MPDFK)); $ly1 = (($this->h-($lk[1]/_MPDFK))); if ($rotate == 90) { $adjx = -($lx1-$bbox_x) + ($preroth - ($ly1-$bbox_y)); $adjy = -($ly1-$bbox_y) + ($lx1-$bbox_x); $lk[2] = -$lk[2]; } else if ($rotate == -90) { $adjx = -($lx1-$bbox_x) + ($ly1-$bbox_y); $adjy = -($ly1-$bbox_y) - ($lx1-$bbox_x) + $prerotw; $lk[3] = -$lk[3]; } if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; } if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; } $lx1 += $adjx; $ly1 += $adjy; $lk[0] = $lx1*_MPDFK; $lk[1] = ($this->h-$ly1)*_MPDFK; } if ($shrink_f != 1) { // i.e. autofit has resized the box $lx1 = (($lk[0]/_MPDFK)-$x); $lx2 = $x + ($lx1 * $shrink_f); $lk[0] = $lx2*_MPDFK; $ly1 = (($this->h-($lk[1]/_MPDFK))-$y); $ly2 = $y + ($ly1 * $shrink_f); $lk[1] = ($this->h-$ly2)*_MPDFK; $lk[2] *= $shrink_f; // width $lk[3] *= $shrink_f; // height } $this->PageLinks[$this->page][]=$lk; } foreach($this->HTMLheaderPageForms AS $n=>$f) { if ($shrink_f != 1) { // i.e. autofit has resized the box $f['x'] = $x + (($f['x'] -$x) * $shrink_f); $f['y'] = $y + (($f['y'] -$y) * $shrink_f); $f['w'] *= $shrink_f; $f['h'] *= $shrink_f; $f['style']['fontsize'] *= $shrink_f; } $this->form->forms[$f['n']] = $f; } // Page Annotations foreach($this->HTMLheaderPageAnnots AS $lk) { if ($rotate) { if ($rotate == 90) { $adjx = -($lk['x']-$bbox_x) + ($preroth - ($lk['y']-$bbox_y)); $adjy = -($lk['y']-$bbox_y) + ($lk['x']-$bbox_x); } else if ($rotate == -90) { $adjx = -($lk['x']-$bbox_x) + ($lk['y']-$bbox_y); $adjy = -($lk['y']-$bbox_y) - ($lk['x']-$bbox_x) + $prerotw; } if ($rot_rpos !== false) { $adjx += $prerotw - $preroth; } if ($rot_bpos !== false) { $adjy += $preroth - $prerotw; } $lk['x'] += $adjx; $lk['y'] += $adjy; } if ($shrink_f != 1) { // i.e. autofit has resized the box $lk['x'] = $x + (($lk['x']-$x) * $shrink_f); $lk['y'] = $y + (($lk['y']-$y) * $shrink_f); } $this->PageAnnots[$this->page][]=$lk; } // Restore $this->headerbuffer = ''; $this->HTMLheaderPageLinks = array(); $this->HTMLheaderPageAnnots = array(); $this->HTMLheaderPageForms = array(); $this->pageBackgrounds = $save_bgs; $this->writingHTMLheader = false; $this->writingHTMLfooter = false; $this->fullImageHeight = false; $this->ResetMargins(); $this->pgwidth = $this->w - $this->lMargin - $this->rMargin; $this->SetXY($save_x,$save_y) ; $this->title2annots = $save_annots; // *ANNOTATIONS* $this->InFooter = false; // turns back on autopagebreaks $this->pageoutput[$this->page]=array(); $this->pageoutput[$this->page]['Font']=''; /*-- COLUMNS --*/ if ($save_cols) { $this->SetColumns($save_nbcol,$this->colvAlign,$this->ColGap); } /*-- END COLUMNS --*/ }
public static function caculateVehiclePrice($vehicle, $distance, $total_pass) { $result = array(); $vehicle_params = json_decode($vehicle->params, true); $result['fare'] = $vehicle->price + $vehicle_params['price_per_distance'] * $distance; $result['qty'] = CEIL($total_pass / $vehicle->seat); $result['total'] = $result['fare'] * $result['qty']; return $result; }
echo "<div class='wrapper' style='overflow:visible'>\n <div class='container' style='overflow:visible'>"; connect(); // recur = 0 not recurring, recur = 1 daily, recur = 2 weekly, recur = 3 monthly, $numPerPage = 10; if (isset($_GET["s"]) && is_numeric($_GET["s"])) { $start = $_GET["s"]; } else { $start = 0; } //$countquery = "SELECT id, COUNT(id) FROM `downtoz0_cms`.`events` WHERE `feature` = '' && `hide` = FALSE && `end_date` >= CURDATE()"; // (we're 5 hours behind utc) $countquery = "SELECT id, COUNT(id) FROM `downtoz0_cms`.`events` WHERE `feature` = ''"; // (we're 5 hours behind utc) $numrows = mysql_query($countquery) or die(mysql_error()); $rower = mysql_fetch_array($numrows); $rowser = $rower['COUNT(id)']; $numberOfPages = CEIL($rowser / $numPerPage); if (isset($_GET["p"]) && is_numeric($_GET["p"])) { $pages = $_GET["p"]; } else { if ($rowser > $numPerPage) { $pages = $numberOfPages; } else { $pages = 1; } } // end p if // EVENTS $events = mysql_query("SELECT *, DATE_FORMAT(date, '%a') as day, DATE_FORMAT(date, '%b') as month FROM `downtoz0_cms`.`events` WHERE `feature` = '' && `hide` = FALSE && `end_date` >= CURDATE() ORDER BY `date` ASC LIMIT {$start}, {$numPerPage}"); $rows = mysql_num_rows($events); if ($rows > 0) { // show data
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality; * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderBackendPage(S $objPageToRender) { // Get a specific CSS file for this controller ... TPL::manageCSS(new FilePath($this->getPathToSkinCSS()->toRelativePath() . $objPageToRender . CSS_EXTENSION), $objPageToRender); // Do pagination ... if (isset($_GET[ADMIN_PAGINATION])) { $objLowerLimit = (int) $_GET[ADMIN_PAGINATION]->toString() * 10 - 10; $objUpperLimit = 10; } else { $objLowerLimit = 0; $objUpperLimit = 10; } // Do a switch on the rendered page ... switch ($objPageToRender) { case 'manageArticles': // Check if there's an action to take; if (isset($_GET[ADMIN_ACTION])) { // Do a switch ... switch ($_GET[ADMIN_ACTION]) { case ADMIN_ACTION_EDIT: $this->renderForm(new S('articleEdit')); break; case ADMIN_ACTION_ERASE: $this->renderForm(new S('articleErase')); break; } } else { // Redirect to DescByPublished ... if (!isset($_GET[ADMIN_ACTION_SORT])) { $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SORT)), new A(array('DescByPublished'))), new S('Location')); } // Set some requirements ... $objGetCondition = new S(); if (isset($_GET[ADMIN_ACTION_BY])) { // Do a switch ... switch ($_GET[ADMIN_ACTION_BY]) { case ARTICLES_SEARCH_TITLE: $objGetCondition->appendString(_SP)->appendString('WHERE %objArticleTableFTitle'); break; case ARTICLES_SEARCH_CONTENT: $objGetCondition->appendString(_SP)->appendString('WHERE %objArticleTableFContent'); break; case ARTICLES_SEARCH_TAGS: $objGetCondition->appendString(_SP)->appendString('WHERE %objArticleTableFTags'); break; case ARTICLES_SEARCH_EXCERPT: $objGetCondition->appendString(_SP)->appendString('WHERE %objArticleTableFExcerpt'); break; case ARTICLES_SEARCH_CATEGORY: $objGetCondition->appendString('AS t1 INNER JOIN %objCategoryTable AS t2 ON t1.%objArticleTableFCategoryId = t2.%objCategoryTableFId WHERE %objCategoryTableFName'); break; } // Add LIKE searching ... $objGetCondition->appendString(_SP)->appendString('LIKE "%%Search%"')->doToken('%Search', $_GET[ADMIN_ACTION_SEARCH]); // Get the count ... $objSearchCount = $this->getArticleCount($objGetCondition); } // Do a sorting, before anything else; if (isset($_GET[ADMIN_ACTION_SORT])) { // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByTitle': case 'DescByTitle': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ORDER BY %objArticleTableFTitle'); // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByTitle': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByTitle': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByPublished': case 'DescByPublished': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ORDER BY %objArticleTableFDatePublished'); // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByPublished': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByPublished': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByUpdated': case 'DescByUpdated': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ORDER BY %objArticleTableFDateUpdated'); // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByUpdated': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByUpdated': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByViews': case 'DescByViews': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ORDER BY %objArticleTableFViews'); // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByViews': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByViews': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByCategory': case 'DescByCategory': if (isset($_GET[ADMIN_ACTION_BY])) { if ($_GET[ADMIN_ACTION_BY] == ARTICLES_SEARCH_CATEGORY) { // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ORDER BY t2.%objCategoryTableFName'); } else { // Make the ordered condition; $objGetCondition->doToken('WHERE', _SP . 'AS t1 INNER JOIN %objCategoryTable AS t2 ON t1.%objArticleTableFCategoryId = t2.%objCategoryTableFId WHERE'); $objGetCondition->appendString(_SP)->appendString('ORDER BY t2.%objCategoryTableFName'); } } else { // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('AS t1 INNER JOIN %objCategoryTable AS t2 ON t1.%objArticleTableFCategoryId = t2.%objCategoryTableFId ORDER BY t2.%objCategoryTableFName'); } // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByCategory': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByCategory': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; } } // Add some LIMITs $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit); // Get based on SQL condtion ... $objArticleTable = $this->getArticles($objGetCondition); if (isset($_GET[ADMIN_ACTION_BY])) { $objArticleTableCount = $objSearchCount; } else { $objArticleTableCount = $this->getArticleCount(); } // Fix pagination when count is LESS than 10; if (isset($_GET[ADMIN_ACTION_BY]) && isset($_GET[ADMIN_PAGINATION])) { if ($objArticleTableCount->toInt() < 10) { // Remove paging ... & redirect to proper ... TPL::setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGINATION))), new S('Location')); } else { if (CEIL($objArticleTableCount->toInt() / 10) < (int) $_GET[ADMIN_PAGINATION]->toString()) { // Redirect to proper ... TPL::setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGINATION)), new A(array(CEIL($objArticleTableCount->toInt() / 10)))), new S('Location')); } } } // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageArticles.tp'); TPL::tpSet($objArticleTable, new S('articleTable'), $tpF); TPL::tpSet($this, new S('ART'), $tpF); TPL::tpSet($this->STG, new S('STG'), $tpF); TPL::tpExe($tpF); // Do pagination ... if ($objArticleTableCount->toInt() > 10) { self::$objAdministration->setPagination($objArticleTableCount); } // Do the form, make it happen; $this->renderForm(new S('articleSearch')); $this->renderForm(new S('articleCreate')); } // BK; break; case 'manageCategories': // Add some requirements; TPL::manageJSS(new FilePath($this->getPathToSkinJSS()->toRelativePath() . 'manageCategories.js'), new S('manageCategories')); // Check if there's an action to take; if (isset($_GET[ADMIN_ACTION])) { // Do a switch ... switch ($_GET[ADMIN_ACTION]) { case ADMIN_ACTION_EDIT: $this->renderForm(new S('categoryEdit')); break; case ADMIN_ACTION_ERASE: $this->renderForm(new S('categoryErase')); break; case ADMIN_ACTION_MOVE: $this->renderForm(new S('categoryMove')); break; } } else { // Set some requirements ... $objGetCondition = new S(); // Do a sorting, before anything else; if (isset($_GET[ADMIN_ACTION_SORT])) { // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByCategory': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByCategory': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('DESC'); break; } } // Add some LIMITs $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit); // Set some requirements ... $objCategoryTreeCount = $this->getCategoryCount(); $objCategoryTree = $this->getCategories(isset($_GET[ADMIN_SHOW_ALL]) ? new S() : $objGetCondition); // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageCategories.tp'); TPL::tpSet($objCategoryTree, new S('categoryTree'), $tpF); TPL::tpExe($tpF); // Do pagination ... if ($objCategoryTreeCount->toInt() > 10 && !isset($_GET[ADMIN_SHOW_ALL])) { self::$objAdministration->setPagination($objCategoryTreeCount); } // Do the form, make it happen; $this->renderForm(new S('categoryCreate')); } // BK; break; case 'manageComments': // Check if there's an action to take; if (isset($_GET[ADMIN_ACTION])) { // Switch between actions; switch ($_GET[ADMIN_ACTION]) { case ADMIN_ACTION_EDIT: $this->renderForm(new S('commentEdit')); break; case ADMIN_ACTION_ERASE: $this->renderForm(new S('commentErase')); break; } } else { // Do a redirect ... if (!isset($_GET[ADMIN_ACTION_SORT])) { $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SORT)), new A(array('DescByDate'))), new S('Location')); } // Set some requirements ... $objGetCondition = new S(); // Do a sorting, before anything else; if (isset($_GET[ADMIN_ACTION_SORT])) { // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByName': case 'DescByName': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ORDER BY %objCommentsTableFName'); // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByName': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByName': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByTitle': case 'DescByTitle': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('AS t1 LEFT JOIN %objArticleTable AS t2 ON t1.%objCommentsTableFArticleId = t2.%objArticleTableFId ORDER BY t2.%objArticleTableFTitle'); // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByTitle': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByTitle': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByApproved': case 'DescByApproved': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ORDER BY %objCommentsTableFApproved'); // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByApproved': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByApproved': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByDate': case 'DescByDate': // Make the ordered condition; $objGetCondition->appendString(_SP)->appendString('ORDER BY %objCommentsTableFDate'); // Do a switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByDate': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByDate': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; } } // Add some LIMITs $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit); // Set some requirements; $objComments = $this->getComments($objGetCondition); $objCommentsCount = $this->getCommentCount(); // Process them arrays; foreach ($objComments as $k => $v) { if ($v[self::$objCommentsTableFRUId] != new S('0')) { $v[self::$objCommentsTableFName] = $this->ATH->getUserInfoById($v[self::$objCommentsTableFRUId], Authentication::$objAuthUsersTableFUName); } } // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageComments.tp'); TPL::tpSet($objComments, new S('articleTable'), $tpF); TPL::tpSet($this->STG, new S('STG'), $tpF); TPL::tpSet($this, new S('ART'), $tpF); TPL::tpExe($tpF); // Do some pagination ... if ($objCommentsCount->toInt() > 10) { self::$objAdministration->setPagination($objCommentsCount); } } // BK; break; case 'manageOperations': // Do the form, make it happen; $this->renderForm(new S('categoryMoveOperation')); break; case 'manageConfiguration': // Do the form, make it happen ... if (isset($_GET[ADMIN_ACTION])) { $this->renderForm($_GET[ADMIN_ACTION]); } else { $this->renderForm(new S('configurationEdit')); } break; } }
/** * Will render a specified form, the name of the form given by the first parameter; * * This method will render one of the forms for our object, invoked by giving the proper form identifier to the current form. * We have chosen this method of invoking forms, because we just had too many this->renderSomethingMethod (), which really had * an impact on code massiveness. Also, having code organized in switch/case statements leads us to be able to share common * settings between different forms, as we've done with the methods defined in the __CALL method above; * * For example, if we wanted to share some common configuration between a create and an edit form, we could have introduced * two switches in this method, one that would have set the common options, and the second, would have just passed through * again, and get the already set configuration options, using them. This means that if we needed to change behavior of * some interconnected forms, that would mean modifying the needed code one place only, which is a big advantage over * having separated methods for each form. Maybe if we extended this object, you guys could understand the functionality ... * * @param string $objFormToRender The name of the form to render; * @return mixed Depends on the rendered form if it returns something or not; */ public function renderBackendPage(S $objPageToRender) { // Get a specific CSS file for this controller ... TPL::manageCSS(new FilePath($this->getPathToSkinCSS()->toRelativePath() . $objPageToRender . CSS_EXTENSION), $objPageToRender); // Do pagination ... if (isset($_GET[ADMIN_PAGINATION])) { $objLowerLimit = (int) $_GET[ADMIN_PAGINATION]->toString() * 10 - 10; $objUpperLimit = 10; } else { $objLowerLimit = 0; $objUpperLimit = 10; } // Do a switch on the rendered page ... switch ($objPageToRender) { case 'welcomePage': // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'welcomePage.tp'); TPL::tpSet(self::$objAdministration->getWidget(NULL), new S('objWidgets'), $tpF); TPL::tpExe($tpF); break; case 'manageUsers': // Do specific actions, based on _GET parameters; if (isset($_GET[ADMIN_ACTION])) { // Switch ... switch ($_GET[ADMIN_ACTION]) { case ADMIN_ACTION_EDIT: $this->renderForm(new S('userEdit')); break; case ADMIN_ACTION_ERASE: $this->renderForm(new S('userErase')); break; } } else { // Show them ordered by DESC; if (!isset($_GET[ADMIN_ACTION_SORT])) { $this->setHeaderKey(URL::rewriteURL(new A(array(ADMIN_ACTION_SORT)), new A(array('DescByRegistered'))), new S('Location')); } // Set some requirements; $objGetCondition = new S(); if (isset($_GET[ADMIN_ACTION_BY])) { // Do a switch ... switch ($_GET[ADMIN_ACTION_BY]) { case AUTHENTICATION_PROFILE_USERNAME: $objGetCondition->appendString('WHERE %objAuthUsersTableFUName'); break; case AUTHENTICATION_PROFILE_EMAIL: $objGetCondition->appendString('WHERE %objAuthUsersTableFEML'); break; case AUTHENTICATION_PROFILE_GROUP: $objGetCondition->appendString('AS t1 LEFT JOIN %objAuthGroupTable AS t2 ON t1.%objAuthUsersTableFUGId = t2.%objAuthGroupTableFId WHERE t2.%objAuthGroupTableFName'); break; } // Add LIKE searching ... $objGetCondition->appendString(_SP)->appendString('LIKE "%%Search%"')->doToken('%Search', $_GET[ADMIN_ACTION_SEARCH]); } if (isset($_GET[ADMIN_ACTION_SORT])) { // Switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByUsername': case 'DescByUsername': // Set the order ... $objGetCondition->appendString(_SP)->appendString('ORDER BY %objAuthUsersTableFUName'); // Switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByUsername': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByUsername': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByEMail': case 'DescByEMail': // Set the order ... $objGetCondition->appendString(_SP)->appendString('ORDER BY %objAuthUsersTableFEML'); // Switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByEMail': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByEMail': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByGroup': case 'DescByGroup': // Set the order ... if (isset($_GET[ADMIN_ACTION_BY])) { $objGetCondition->appendString(_SP)->prependString('AS t1 LEFT JOIN %objAuthGroupTable AS t2 ON t1.%objAuthUsersTableFUGId = t2.%objAuthGroupTableFId '); } else { $objGetCondition->appendString(_SP)->appendString('AS t1 LEFT JOIN %objAuthGroupTable AS t2 ON t1.%objAuthUsersTableFUGId = t2.%objAuthGroupTableFId '); } // Add order by ... $objGetCondition->appendString(_SP)->appendString('ORDER BY t2.%objAuthGroupTableFName'); // Switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByGroup': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByGroup': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByRegistered': case 'DescByRegistered': // Set the order ... $objGetCondition->appendString(_SP)->appendString('ORDER BY %objAuthUsersTableFRegOn'); // Switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByRegistered': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByRegistered': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; } } // Make the unordered condition; $objGetCondition = $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit); // Get the users ... $objUsersTable = $this->getUsers($objGetCondition); if (isset($_GET[ADMIN_ACTION_BY])) { $objUsersTableCount = $objUsersTable->doCount(); } else { $objUsersTableCount = $this->getUserCount(); } // Get each group for each user ... foreach ($objUsersTable as $k => $v) { $v['group_name'] = $this->getGroupInfoById($v[Authentication::$objAuthUsersTableFUGId], Authentication::$objAuthGroupTableFName); } // Fix pagination when count is LESS than 10; if (isset($_GET[ADMIN_ACTION_BY]) && isset($_GET[ADMIN_PAGINATION])) { if ($objUsersTableCount->toInt() < 10) { // Remove paging ... & redirect to proper ... TPL::setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGINATION))), new S('Location')); } else { if (CEIL($objUsersTableCount->toInt() / 10) < (int) $_GET[ADMIN_PAGINATION]->toString()) { // Redirect to proper ... TPL::setHeaderKey(URL::rewriteURL(new A(array(ADMIN_PAGINATION)), new A(array(CEIL($objUsersTableCount->toInt() / 10)))), new S('Location')); } } } // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageUsers.tp'); TPL::tpSet($objUsersTable, new S('usersTable'), $tpF); TPL::tpSet($this->STG, new S('STG'), $tpF); TPL::tpExe($tpF); // Do them pagination ... if ($objUsersTableCount->toInt() > 10) { self::$objAdministration->setPagination($objUsersTableCount); } // Set a search form; $this->renderForm(new S('userSearch')); $this->renderForm(new S('userCreate')); } break; case 'manageGroups': // Add some requirements; TPL::manageJSS(new FilePath($this->getPathToSkinJSS()->toRelativePath() . 'manageGroups.js'), new S('manageCategories')); // Do specific actions, based on _GET parameters; if (isset($_GET[ADMIN_ACTION])) { switch ($_GET[ADMIN_ACTION]) { case ADMIN_ACTION_EDIT: $this->renderForm(new S('groupEdit')); break; case ADMIN_ACTION_ERASE: $this->renderForm(new S('groupErase')); break; case ADMIN_ACTION_MOVE: $this->renderForm(new S('groupMove')); break; } } else { // Do an empty SQL string; $objGetCondition = new S(); // Do a sorting, before anything else; if (isset($_GET[ADMIN_ACTION_SORT])) { switch ($_GET[ADMIN_ACTION_SORT]) { case 'DescByGroup': $objGetCondition->appendString(_SP)->appendString('DESC'); break; case 'AscByGroup': $objGetCondition->appendString(_SP)->appendString('ASC'); break; } } // Add some LIMITs; $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit); // Set some requirements; $objGroupTable = $this->getGroups(isset($_GET[ADMIN_SHOW_ALL]) ? new S() : $objGetCondition); $objGroupTableCount = $this->getGroupCount(); // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageGroups.tp'); TPL::tpSet($objGroupTable, new S('groupTree'), $tpF); TPL::tpExe($tpF); // Do them paginations ... if ($objGroupTableCount->toInt() > 10 && !isset($_GET[ADMIN_SHOW_ALL])) { self::$objAdministration->setPagination($objGroupTableCount); } // Do the form, make it happen; $this->renderForm(new S('groupCreate')); } break; case 'manageZones': // Do specific actions, based on _GET parameters; if (isset($_GET[ADMIN_ACTION])) { // Switch ... switch ($_GET[ADMIN_ACTION]) { case ADMIN_ACTION_EDIT: $this->renderForm(new S('zoneEdit')); break; case ADMIN_ACTION_ERASE: $this->renderForm(new S('zoneErase')); break; } } else { // Do a sorting beforehand; $objGetCondition = new S(); if (isset($_GET[ADMIN_ACTION_SORT])) { switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByZone': case 'DescByZone': // Switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByZone': $objGetCondition->appendString(_SP)->appendString(new S('ASC')); break; case 'DescByZone': $objGetCondition->appendString(_SP)->appendString(new S('DESC')); break; } break; } } // Add some LIMITs $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit); // Set some requirements; $objZonesTable = $this->getZones($objGetCondition); $objZonesTableCount = $this->getZoneCount(); // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageZones.tp'); TPL::tpSet($objZonesTable, new S('zonesTable'), $tpF); TPL::tpExe($tpF); // Do them paginations ... if ($objZonesTableCount->toInt() > 10) { self::$objAdministration->setPagination($objZonesTableCount); } } break; case 'manageMappings': // Do specific actions, based on _GET parameters; if (isset($_GET[ADMIN_ACTION])) { switch ($_GET[ADMIN_ACTION]) { case ADMIN_ACTION_EDIT: $this->renderForm(new S('zoneMappingEdit')); break; case ADMIN_ACTION_ERASE: $this->renderForm(new S('zoneMappingErase')); break; } } else { // Do a sorting beforehand; $objGetCondition = new S(); if (isset($_GET[ADMIN_ACTION_SORT])) { // Switch ... switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByGroup': case 'DescByGroup': // Set some requirements; $objGetCondition->appendString(_SP)->appendString('AS t1 LEFT JOIN %objAuthGroupTable AS t2 ON t1.%objAuthZoneMTableFUGId = t2.%objAuthGroupTableFId ORDER BY t2.%objAuthGroupTableFName'); switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByGroup': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByGroup': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByZoneForGroup': case 'DescByZoneForGroup': // Set some requirements; $objGetCondition = new S('AS t1 LEFT JOIN %objAuthZonesTable AS t2 ON t1.%objAuthZoneMTableFZId = t2.%objAuthGroupTableFId ORDER BY t2.%objAuthZonesTableFName'); switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByZoneForGroup': $objGetCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByZoneForGroup': $objGetCondition->appendString(_SP)->appendString('DESC'); break; } break; } } // LIMIT only TO GROUP; if ($objGetCondition->toLength()->toInt() != 0) { $objGetCondition->doToken('ORDER', new S('WHERE %objAuthZoneMTableFIUG = "Y" ORDER')); } else { $objGetCondition = new S('WHERE %objAuthZoneMTableFIUG = "Y"'); } // Add SOME LIMITs; $objGetCondition->appendString(_SP)->appendString('LIMIT %LowerLimit, %UpperLimit')->doToken('%LowerLimit', $objLowerLimit)->doToken('%UpperLimit', $objUpperLimit); // Set some requirements; $objZoneMappings = $this->getZoneMappings($objGetCondition); $objMappingsTableCount = $this->getMappingCount(new S('WHERE %objAuthZoneMTableFIUG = "Y"')); // Set the template file ... $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageMappings.tp'); TPL::tpSet($objZoneMappings, new S('zonesMappingsTableForGroup'), $tpF); TPL::tpExe($tpF); // Do pagination; if ($objMappingsTableCount->toInt() > 10) { self::$objAdministration->setPagination($objMappingsTableCount); } // Do the form, make it happen; $this->renderForm(new S('zoneMappingCreateForGroups')); } break; case 'manageMappingsForUsers': // Do specific actions, based on _GET parameters; if (isset($_GET[ADMIN_ACTION])) { switch ($_GET[ADMIN_ACTION]) { case ADMIN_ACTION_EDIT: $this->renderForm(new S('zoneMappingEdit')); break; case ADMIN_ACTION_ERASE: $this->renderForm(new S('zoneMappingErase')); break; } } else { // Do a sorting beforehand; $objGetUCondition = new S(); if (isset($_GET[ADMIN_ACTION_SORT])) { switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByZone': case 'DescByZone': // Set some requirements; $objGetUCondition = new S('AS t1 LEFT JOIN %objAuthZonesTable AS t2 ON t1.%objAuthZoneMTableFZId = t2.%objAuthUsersTableFId ORDER BY t2.%objAuthZonesTableFName'); switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByZone': $objGetUCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByZone': $objGetUCondition->appendString(_SP)->appendString('DESC'); break; } break; case 'AscByUsername': case 'DescByUsername': // Set some requirements; $objGetUCondition = new S('AS t1 LEFT JOIN %objAuthUsersTable AS t2 ON t1.%objAuthZoneMTableFUGId = t2.%objAuthUsersTableFId ORDER BY t2.%objAuthUsersTableFUName'); switch ($_GET[ADMIN_ACTION_SORT]) { case 'AscByUsername': $objGetUCondition->appendString(_SP)->appendString('ASC'); break; case 'DescByUsername': $objGetUCondition->appendString(_SP)->appendString('DESC'); break; } break; } } // LIMIT ONLY to USERS; if ($objGetUCondition->toLength()->toInt() != 0) { $objGetUCondition->doToken('ORDER', new S('WHERE %objAuthZoneMTableFIUG = "N" ORDER')); } else { $objGetUCondition = new S('WHERE %objAuthZoneMTableFIUG = "N"'); } // Set some requirements; $objMappingsTableCount = $this->getMappingCount(new S('WHERE %objAuthZoneMTableFIUG = "N"')); $objZoneMappings = $this->getZoneMappings($objGetUCondition); // Set the template file; $tpF = new FilePath($this->getPathToSkin()->toRelativePath() . 'manageMappingsForUsers.tp'); TPL::tpSet($objZoneMappings, new S('zonesMappingsTableForUsers'), $tpF); TPL::tpExe($tpF); // Do pagination; if ($objMappingsTableCount->toInt() > 10) { self::$objAdministration->setPagination($objMappingsTableCount); } // Do the form, make it happen; $this->renderForm(new S('zoneMappingCreateForUsers')); } // Break out; break; case 'manageConfiguration': if (isset($_GET[ADMIN_ACTION])) { $this->renderForm($_GET[ADMIN_ACTION]); } else { $this->renderForm(new S('configurationEdit')); } break; } }
<?php if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } $rows_per_page = 10; $limit = "LIMIT" . " " . ($pageno - 1) * $rows_per_page . "," . $rows_per_page; $a = mysqli_connect("localhost", "root", "", "wp101"); $b = "select count(*) from wp_posts"; $c = mysqli_query($a, $b); $d = mysqli_fetch_array($c); $count = $d[0]; $total_page = $count / $rows_per_page; $total_page = CEIL($total_page); $a = mysqli_connect("localhost", "root", "", "wp101"); $b = "select * from wp_posts {$limit}"; $c = mysqli_query($a, $b); ?> <table border="2"> <?php while ($d = mysqli_fetch_array($c)) { print_R($d); ?> <tr> <td><?php echo $d[0]; ?> </td>