/** * @param string $culture_code Code of current <CultureInfo> * @param mixed $date_format Chosen date format * @param mixed $time_format Chosen time format * @param string $timezone Currently chosen timezone * @param bool $append_timezone If true timezome will be appended */ function __initialize($culture_code, $date_format, $time_format, $timezone = false, $append_timezone = false) { parent::__initialize(); $this->script("Locale_Settings_Init();"); store_object($this); if (!$timezone) { $timezone = Localization::getTimeZone(); } $this->timezone = $timezone; $this->culture_code = $culture_code; $txt = $this->_sample(false, $date_format, $time_format); if ($append_timezone) { $txt .= " {$timezone}"; } $sample = new Control('span'); $sample->append("({$txt})")->css('color', 'gray'); $cb = new CheckBox(); $cb->setData('role', 'timeformatex')->setData('controller', buildQuery($this->id)); $cb->value = 1; if ($append_timezone) { $cb->checked = "checked"; } $lab = $cb->CreateLabel(tds("TXT_APPEND_TIMEZONE", "Append timezone") . " "); $lab->content($sample); $this->append($cb)->append($lab); }
/** * @param string $message_text Message text * @param string $type Defines the css class, so you may use this to style different kinds of messages * @param string $title A title */ function __initialize($message_text, $type = 'hint', $title = 'TITLE_WARNING') { $options = array('autoOpen' => true, 'modal' => true, 'width' => 450, 'height' => 300); parent::__initialize($title, $options); $this->class = $type; $this->content($message_text); $this->AddCloseButton(tds('BTN_OK', 'Ok')); }
/** * Set the callback for the positive button. * * @param string $action JS code to be executed when the positive button is clicked (OK, YES) * @return uiConfirmation `$this` */ function SetOkCallback($action) { switch ($this->Mode) { case self::OK_CANCEL: $this->SetButton(tds('BTN_OK', 'Ok'), $action); break; case self::YES_NO: $this->SetButton(tds('BTN_YES', 'Yes'), $action); break; } return $this; }
/** * @param mixed $current_language_code Currently selected language * @param type $current_region_code Currently selected region */ function __initialize($current_language_code = false, $current_region_code = false) { parent::__initialize(); $this->script("Locale_Settings_Init();"); $this->setData('role', 'region'); $this->setData('controller', buildQuery($this->id)); if ($current_language_code) { if ($current_language_code instanceof CultureInfo) { $lang = $current_language_code->ResolveToLanguage(); } else { $lang = Localization::getLanguageCulture($current_language_code); } if (!$lang) { $lang = Localization::detectCulture()->ResolveToLanguage(); } $regions = $lang->GetRegions(false); if (!$current_region_code) { $current_region_code = $lang->DefaultRegion()->Code; } } else { $regions = Localization::get_all_regions(false); } if ($current_region_code) { if ($current_region_code instanceof CultureInfo) { $this->SetCurrentValue($current_region_code->DefaultRegion()->Code); } else { $this->SetCurrentValue($current_region_code); } } if (count($regions) > 0) { $cc = current_controller(false); $translations_active = $cc instanceof Renderable && $cc->_translate; $sorted = array(); foreach ($regions as $reg) { if (!$reg) { continue; } $code = $reg->Code; if ($translations_active) { $sorted[$code] = array("name" => tds("TXT_COUNTRY_" . strtoupper($code), $reg->EnglishName), "code", $code); } else { $sorted[$code] = array("name" => $reg->EnglishName, "code", $code); } } uasort($sorted, __CLASS__ . "::compareCountryNames"); foreach ($sorted as $code => $item) { $this->AddOption($code, $item['name']); } } }
} $html = file_get_html($url); $uniques = array(); //Previous table's name, needed because of a bug in the webpage $table_name_prev = "t1"; //Table contents foreach (tables($html) as $table) { $table_name = $table->id; foreach (trs($table) as $tr) { if ($tr->find('th')) { //Skip the header rows. (There are two per table, and they are formatted differently.) //Later, we can add something to rename the columns based on headers continue; } else { $row = array(); foreach (tds($tr) as $td) { $key_raw = $td->headers; //If the previous table's name is used in the attribute, replace it with the current name $key = str_replace($table_name_prev, $table_name, $key_raw); unset($key_raw); $value = $td->plaintext; if ($key != '') { $row[$key] = $value; } } scraperwiki::save_sqlite($uniques, $row, $table_name); unset($row); } } $table_name_prev = $table_name; unset($table_name);
/** * @override */ function PreRender($args = array()) { if (count($this->_data) > 1) { $id = $this->id; $opts = json_encode($this->gvOptions); if (count($this->_data) > 0) { array_walk_recursive($this->_data, function (&$item, &$key) { if ($item instanceof DateTime) { $item = "[jscode]new Date(" . $item->getTimestamp() * 1000 . ")"; } }); $d = system_to_json($this->_data); $js = "var d=google.visualization.arrayToDataTable({$d});" . "var c=new google.visualization.{$this->gvType}(\$('#{$id}').get(0));" . "google.visualization.events.addListener(c, 'ready', function(){ \$('#{$id}').data('ready',true); });" . "c.draw(d,{$opts});" . "\$('#{$id}').data('googlechart', c);"; } else { $q = buildQuery($this->id, 'Query'); $js = "var {$id} = new google.visualization.Query('{$q}');" . "{$id}.setQuery('{$this->gvQuery}');" . "{$id}.send(function(r){ if(r.isError()){ \$('#{$id}').html(r.getDetailedMessage()); }else{ var c=new google.visualization.{$this->gvType}(\$('#{$id}').get(0));" . "google.visualization.events.addListener(c, 'ready', function(){ \$('#{$id}').data('ready',true); });" . "c.draw(r.getDataTable(),{$opts});" . "\$('#{$id}').data('googlechart', c);}});"; } $this->_addLoadCallback('visualization', $js, true); } else { $t = $this->opt('title'); $this->css('text-align', 'center')->content(($t ? "<b>{$t}:</b> " : "") . tds("TXT_NO_DATA", "No data found"), true); } if (isset($this->gvOptions['width'])) { $this->css('width', "{$this->gvOptions['width']}px"); } if (isset($this->gvOptions['height'])) { $this->css('height', "{$this->gvOptions['height']}px"); } return parent::PreRender($args); }
function Prepare($async = false, &$handler = false, $method = false) { global $CONFIG; if ($async) { if (!$handler || !$method) { WdfException::Raise("Data handler and method needed for asynchronous charts"); } $data_url = buildQuery($handler->id, $method); } else { if ($handler && $method) { $data = $handler->{$method}($this); } // else // $data = $this->CleanupXML($this->RenderXML()); } $str_data = $this->Title ? $this->Title : ''; $swfurl = $CONFIG['system']['system_uri'] . appendVersion("/modules/charting/charts/" . $this->Type . ".swf"); $swfurl .= "?PBarLoadingText=" . urlencode($str_data . ":\n" . getString(tds("TXT_CHART_LOADING", 'loading'))); $swfurl .= "&ChartNoDataText=" . urlencode($str_data . ":\n" . getString(tds("TXT_NO_DATA_FOUND", 'no data found'))); $swfurl .= "&InvalidXMLText=" . urlencode($str_data . ":\n" . getString(tds("TXT_CHART_INVALID_XML", 'invalid XML'))); $settings = array('swfurl' => $swfurl, 'chartid' => $this->id, 'width' => $this->Width, 'height' => $this->Height, 'debug' => 0); if (isset($data)) { $settings['data'] = $data; } elseif (isset($data_url)) { $settings['dataurl'] = $data_url; } $this->_script = array(); $this->script("initFusionChart(" . json_encode($settings) . ");"); }
/** * Syntactically checks a credit card number. * * Valid values for $cardname are returned ny <creditcard_getnames>. * @param type $cardnumber Number to check * @param type $cardname Card name * @param type $errornumber <b>OUT</b> The error number * @param type $errortext <b>OUT</b> The error message * @return boolean true or false */ function creditcard_check($cardnumber, $cardname, &$errornumber, &$errortext) { // Define the cards we support. You may add additional card types. // Name: As in the selection box of the form - must be same as user's // Length: List of possible valid lengths of the card number for the card // prefixes: List of possible prefixes for the card // checkdigit Boolean to say whether there is a check digit // Don't forget - all but the last array definition needs a comma separator! $cards = array(array('name' => 'American Express', 'length' => '15', 'prefixes' => '34,37', 'checkdigit' => true), array('name' => 'Diners Club Carte Blanche', 'length' => '14', 'prefixes' => '300,301,302,303,304,305', 'checkdigit' => true), array('name' => 'Diners Club', 'length' => '14,16', 'prefixes' => '36,54,55', 'checkdigit' => true), array('name' => 'Discover', 'length' => '16', 'prefixes' => '6011,622,64,65', 'checkdigit' => true), array('name' => 'Diners Club Enroute', 'length' => '15', 'prefixes' => '2014,2149', 'checkdigit' => true), array('name' => 'JCB', 'length' => '16', 'prefixes' => '35', 'checkdigit' => true), array('name' => 'Maestro', 'length' => '12,13,14,15,16,18,19', 'prefixes' => '5018,5020,5038,6304,6759,6761', 'checkdigit' => true), array('name' => 'MasterCard', 'length' => '16', 'prefixes' => '51,52,53,54,55', 'checkdigit' => true), array('name' => 'Solo', 'length' => '16,18,19', 'prefixes' => '6334,6767', 'checkdigit' => true), array('name' => 'Switch', 'length' => '16,18,19', 'prefixes' => '4903,4905,4911,4936,564182,633110,6333,6759', 'checkdigit' => true), array('name' => 'Visa', 'length' => '13,16', 'prefixes' => '4', 'checkdigit' => true), array('name' => 'Visa Electron', 'length' => '16', 'prefixes' => '417500,4917,4913,4508,4844', 'checkdigit' => true)); $ccErrorNo = 0; // Unknown card type $ccErrors[0] = tds('ERR_UNKNOWN_CARD_TYPE', 'Unknown card type'); // No card number provided $ccErrors[1] = tds('ERR_NO_CARD_NUMBER_PROVIDED', 'Card number missing'); // Credit card number has invalid format $ccErrors[2] = tds('ERR_CREDIT_CARD_NUMBER_HAS_INVALID_FORMAT', 'Invalid card number format'); // Credit card number is invalid $ccErrors[3] = tds('ERR_CREDIT_CARD_NUMBER_IS_INVALID', 'Invalid card number'); // Credit card number is wrong length $ccErrors[4] = tds('ERR_CREDIT_CARD_NUMBER_IS_WRONG_LENGTH', 'Wrong card number length'); // Establish card type $cardType = -1; for ($i = 0; $i < sizeof($cards); $i++) { // See if it is this card (ignoring the case of the string) if (strtolower($cardname) == strtolower($cards[$i]['name'])) { $cardType = $i; break; } } // If card type not found, report an error if ($cardType == -1) { $errornumber = 0; $errortext = $ccErrors[$errornumber]; return false; } // Ensure that the user has provided a credit card number if (strlen($cardnumber) == 0) { $errornumber = 1; $errortext = $ccErrors[$errornumber]; return false; } // Remove any spaces from the credit card number $cardNo = str_replace(' ', '', $cardnumber); // Check that the number is numeric and of the right sort of length. if (!eregi('^[0-9]{13,19}$', $cardNo)) { $errornumber = 2; $errortext = $ccErrors[$errornumber]; return false; } // Now check the modulus 10 check digit - if required if ($cards[$cardType]['checkdigit']) { $checksum = 0; // running checksum total $mychar = ""; // next char to process $j = 1; // takes value of 1 or 2 // Process each digit one by one starting at the right for ($i = strlen($cardNo) - 1; $i >= 0; $i--) { // Extract the next digit and multiply by 1 or 2 on alternative digits. $calc = $cardNo[$i] * $j; // If the result is in two digits add 1 to the checksum total if ($calc > 9) { $checksum = $checksum + 1; $calc = $calc - 10; } // Add the units element to the checksum total $checksum = $checksum + $calc; // Switch the value of j if ($j == 1) { $j = 2; } else { $j = 1; } } // All done - if checksum is divisible by 10, it is a valid modulus 10. // If not, report an error. if ($checksum % 10 != 0) { $errornumber = 3; $errortext = $ccErrors[$errornumber]; return false; } } // The following are the card-specific checks we undertake. // Load an array with the valid prefixes for this card $prefix = split(',', $cards[$cardType]['prefixes']); // Now see if any of them match what we have in the card number $PrefixValid = false; for ($i = 0; $i < sizeof($prefix); $i++) { $exp = '^' . $prefix[$i]; if (ereg($exp, $cardNo)) { $PrefixValid = true; break; } } // If it isn't a valid prefix there's no point at looking at the length if (!$PrefixValid) { $errornumber = 3; $errortext = $ccErrors[$errornumber]; return false; } // See if the length is valid for this card $LengthValid = false; $lengths = split(',', $cards[$cardType]['length']); for ($j = 0; $j < sizeof($lengths); $j++) { if (strlen($cardNo) == $lengths[$j]) { $LengthValid = true; break; } } // See if all is OK by seeing if the length was valid. if (!$LengthValid) { $errornumber = 4; $errortext = $ccErrors[$errornumber]; return false; } // The credit card is in the required format. return true; }