singularize() public static method

public static singularize ( $string )
Example #1
0
 public function __construct($model = '', $fields = '', $zip = null, $version = '0.6', $norm = true)
 {
     if (empty($model)) {
         trigger_error('Please provide a model');
         exit;
     }
     if (empty($fields)) {
         trigger_error('Please provide fields');
         exit;
     }
     $this->model->lowercase = strtolower($this->computerize(Inflect::singularize($model)));
     $this->model->capital = ucwords($this->computerize(Inflect::singularize($model)));
     $this->models->lowercase = strtolower($this->computerize(Inflect::pluralize($model)));
     $this->models->capital = ucwords($this->computerize(Inflect::pluralize($model)));
     $this->models->table = $this->computerize($this->models->lowercase);
     $this->models->human = $this->humanize($this->models->lowercase);
     $this->models->human_capital = $this->humanize($this->models->capital);
     $this->models->class = ucwords($this->computerize(Inflect::singularize($model), 'camelcase'));
     $this->models->migration = ucwords($this->computerize(Inflect::pluralize($model), 'camelcase'));
     $this->fields = $this->field_cleaner($fields);
     $this->zip = $zip;
     $this->version = $version;
     if ($this->version < '0.6') {
         $this->norm = false;
     } else {
         $this->norm = $norm;
     }
     $this->include_path = $_SERVER['DOCUMENT_ROOT'] . '/tools/_shared/admin_templates/' . $this->version . ($this->norm ? '_norm' : '') . '/';
     if (!file_exists($this->include_path)) {
         trigger_error('AI files for ' . $this->version . ($this->norm ? '_norm' : '') . ' doesn\'t exist.');
         exit;
     }
 }
Example #2
0
 function __construct($route = null)
 {
     parent::__construct($route);
     $controllerClass = $this->getControllerClassName();
     // Create model instance for each registered model in the controller
     if (isset($this->uses)) {
         foreach ($this->uses as $use) {
             $this->{$use} = new $use();
         }
     } else {
         // Default model based on Controller name
         $sing = Inflect::singularize($controllerClass);
         $this->{$sing} = new $sing();
         $this->model = $this->{$sing};
     }
 }
 foreach (array('product_id', 'item_price', 'quantity', 'random_weight', 'total_weight', 'taxable', 'extra_charge', 'out_of_stock') as $field_name) {
     if (${$field_name} != $old_invoice[$product_id][$field_name]) {
         $error[$field_name] = $error_flag;
         $invoice[$field_name] = '<span id="invoice_' . $field_name . '" class="invoice_source">' . htmlspecialchars($old_invoice[$product_id][$field_name], ENT_QUOTES) . '</span>';
         $move_link[$field_name] = '<span id="transfer_' . $field_name . '" class="transfer" onClick="transfer_to_field(\'invoice_' . $field_name . '\',\'update_' . $field_name . '\');update_db(\'' . $field_name . '\');document.getElementById(\'skip\').innerHTML=\' &nbsp; &nbsp; <br>Continue<br> &nbsp; &nbsp; \'">' . $transfer_this . '</span>';
         $update[$field_name] = '<input size="5" id="update_' . $field_name . '" class="update_destination" value="' . htmlentities(${$field_name}) . '" onChange="update_db(\'' . $field_name . '\')">';
         $errors++;
     } else {
         $invoice[$field_name] = htmlspecialchars($old_invoice[$product_id][$field_name], ENT_QUOTES);
         $move_link[$field_name] = '';
         $update[$field_name] = htmlspecialchars(${$field_name}, ENT_QUOTES);
     }
 }
 // These fields must match with consideration for pluralization
 foreach (array('pricing_unit', 'ordering_unit') as $field_name) {
     if (${$field_name} != trim($old_invoice[$product_id][$field_name]) && Inflect::singularize(${$field_name}) != trim($old_invoice[$product_id][$field_name]) && Inflect::pluralize(${$field_name}) != trim($old_invoice[$product_id][$field_name]) && ${$field_name} . 's' != trim($old_invoice[$product_id][$field_name])) {
         $error[$field_name] = $error_flag;
         $invoice[$field_name] = '<span id="invoice_' . $field_name . '" class="invoice_source">' . htmlspecialchars($old_invoice[$product_id][$field_name], ENT_QUOTES) . '</span>';
         $move_link[$field_name] = '<span id="transfer_' . $field_name . '" class="transfer" onClick="transfer_to_field(\'invoice_' . $field_name . '\',\'update_' . $field_name . '\');update_db(\'' . $field_name . '\');document.getElementById(\'skip\').innerHTML=\' &nbsp; &nbsp; <br>Continue<br> &nbsp; &nbsp; \'">' . $transfer_this . '</span>';
         $update[$field_name] = '<input size="15" id="update_' . $field_name . '" class="update_destination" value="' . htmlentities(${$field_name}) . '" onChange="update_db(\'' . $field_name . '\')">';
         $errors++;
     } else {
         $invoice[$field_name] = htmlspecialchars($old_invoice[$product_id][$field_name], ENT_QUOTES);
         $move_link[$field_name] = '';
         $update[$field_name] = htmlspecialchars(${$field_name}, ENT_QUOTES);
     }
 }
 if ($errors > 0) {
     // Only display this stuff if there were errors
     // How many products in this basket? This is used to create a basket-progress bar.
     $query_progress = '
function pricing_display_calc($data)
{
    return ($data['unit_price'] != 0 ? '$&nbsp;' . number_format($data['unit_price'], 2) . '/' . ($data['random_weight'] ? $data['pricing_unit'] : $data['ordering_unit']) : '') . ($data['unit_price'] != 0 && $data['extra_charge'] != 0 ? '<br />' : '') . ($data['extra_charge'] != 0 ? '<span class="extra">' . ($data['extra_charge'] > 0 ? '+' : '-') . '&nbsp;$&nbsp;' . number_format(abs($data['extra_charge']), 2) . '/' . Inflect::singularize($data['ordering_unit']) . '</span><br />' : '');
}
Example #5
0
            }
            if ($a['count'] < $b['count']) {
                return 1;
            }
            return strcasecmp($a['title'], $b['title']);
        });
        foreach ($domains as $domain) {
            ?>
				<li<?php 
            echo isset($domainMap[$domain['title']]) ? ' class="current subsel"' : '';
            ?>
><button type="submit" name="domain" value="<?php 
            echo isset($domainMap[$domain['title']]) ? '' : a($domain['title']);
            ?>
"><?php 
            echo h(p($domain['count'], Inflect::singularize($domain['title'])));
            ?>
</button></li>
			<?php 
        }
        ?>
		</ol>
		</div>
		<table class="facets">
			<tbody>
			<?php 
        $timeframe = array();
        if (isset($_GET['timeframe']) && is_array($_GET['timeframe'])) {
            foreach ($_GET['timeframe'] as $tf) {
                $timeframe[] = array('id' => $tf, 'title' => $tf);
            }
function pricing_display_calc(&$product, &$unique)
{
    $this_row = $product['this_row'];
    $markup = 0;
    if (PAYS_PRODUCER_FEE == 'customer') {
        $markup += $product[$this_row]['producer_fee_percent'];
    }
    if (PAYS_CUSTOMER_FEE == 'customer') {
        $markup += $unique['customer_fee_percent'];
    }
    if (PAYS_SUBCATEGORY_FEE == 'customer') {
        $markup += $product[$this_row]['subcategory_fee_percent'];
    }
    if (PAYS_PRODUCT_FEE == 'customer') {
        $markup += $product[$this_row]['product_fee_percent'];
    }
    if ($unique['invoice_price'] == 1) {
        $unit_price = $product[$this_row]['unit_price'] * (1 + $markup / 100);
    } elseif ($unique['invoice_price'] == 0) {
        $unit_price = $product[$this_row]['unit_price'];
    }
    return '<span class="unit_price">$' . number_format($unit_price, 2) . '/' . Inflect::singularize($product[$this_row]['pricing_unit']) . '</span><br>' . ($product[$this_row]['extra_charge'] != 0 ? '<span class="extra">' . ($product[$this_row]['extra_charge'] > 0 ? '+' : '-') . '&nbsp;$&nbsp;' . number_format(abs($product[$this_row]['extra_charge']), 2) . '/' . Inflect::singularize($product[$this_row]['ordering_unit']) . '</span><br>' : '');
}
Example #7
0
 /**
  * Create a model class name from a plural table name.
  *
  * <code>
  * TipyInflector::classify('blog_posts') // => BlogPost
  * </code>
  * @param string $str
  * @return string
  */
 public static function classify($str)
 {
     $str = self::camelCase($str);
     $str = Inflect::singularize($str);
     return ucfirst($str);
 }
Example #8
0
 /**
  * run_association()
  * 
  * Runs association when requested
  * 
  * @param string $class Class of the association to run
  *
  * @return Association model(s)
  **/
 private function run_association($class)
 {
     $type = key($this->config->associations[$class]);
     $options = $this->config->associations[$class][$type];
     $class_name = $this->classify(Inflect::singularize($options['model']));
     $c = new $class_name();
     // Set the field for lookup
     if (isset($options['field'])) {
         $id_field = $options['field'];
     } else {
         $id_field = $type == 'belongs_to' ? $options['model'] . '_id' : strtolower(get_class($this)) . '_id';
     }
     // Perform search
     list($find, $param) = $type == 'belongs_to' ? array('find_by_id', $this->{$id_field}) : array('find_by_' . $id_field, $this->id);
     $members = $c->order_by(@$options['order_by'])->{$find}($param);
     array_push($this->config->ignore, $class);
     if (empty($members)) {
         return array();
     } else {
         return $type == 'has_many' ? $members : $members[0];
     }
 }
function generate_producer_summary($producer_id, $delivery_id, $detail_type, $use)
{
    global $connection, $include_header, $include_footer, $producer_markdown, $retail_markup, $wholesale_markup;
    $query = '
      SELECT
        *
      FROM
        ' . TABLE_ORDER_CYCLES . '
      WHERE
        delivery_id = ' . mysql_real_escape_string($delivery_id);
    $result = mysql_query("{$query}") or die("Error: " . mysql_error());
    while ($row = mysql_fetch_array($result)) {
        $delivery_date = date("M j, Y", strtotime($row['delivery_date']));
    }
    ///                 OBTAIN PRODUCER BUSINESS AND NAME INFO.                  ///
    $sqlp = '
      SELECT
        ' . TABLE_PRODUCER . '.business_name,
        ' . TABLE_MEMBER . '.first_name,
        ' . TABLE_MEMBER . '.last_name,
        ' . TABLE_MEMBER . '.address_line1,
        ' . TABLE_MEMBER . '.address_line2,
        ' . TABLE_MEMBER . '.city,
        ' . TABLE_MEMBER . '.state,
        ' . TABLE_MEMBER . '.zip,
        ' . TABLE_MEMBER . '.county,
        ' . TABLE_MEMBER . '.email_address,
        ' . TABLE_MEMBER . '.home_phone,
        ' . TABLE_MEMBER . '.work_phone,
        ' . TABLE_MEMBER . '.mobile_phone
      FROM
        ' . TABLE_PRODUCER . ',
        ' . TABLE_MEMBER . '
      WHERE
        ' . TABLE_PRODUCER . '.producer_id = "' . mysql_real_escape_string($producer_id) . '"
        AND ' . TABLE_PRODUCER . '.member_id = ' . TABLE_MEMBER . '.member_id
      GROUP BY
        ' . TABLE_PRODUCER . '.producer_id
      ORDER BY
        business_name ASC,
        last_name ASC';
    $resultp = @mysql_query($sqlp, $connection) or die(debug_print("ERROR: 762930 ", array($sqlp, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
    while ($row = mysql_fetch_array($resultp)) {
        $a_business_name = $row['business_name'];
        $a_first_name = $row['first_name'];
        $a_last_name = $row['last_name'];
        $a_address_line1 = $row['address_line1'];
        $a_address_line2 = $row['address_line2'];
        $a_city = $row['city'];
        $a_state = $row['state'];
        $a_zip = $row['zip'];
        $a_county = $row['county'];
        $a_email_address = $row['email_address'];
        $a_home_phone = $row['home_phone'];
        $a_work_phone = $row['work_phone'];
        $a_mobile_phone = $row['cell_phone'];
    }
    $sqlpr = '
      SELECT
        ' . NEW_TABLE_BASKET_ITEMS . '.*,
        ' . NEW_TABLE_PRODUCTS . '.*,
        ' . TABLE_PRODUCT_STORAGE_TYPES . '.storage_code,
        ' . NEW_TABLE_SITES . '.site_id,
        ' . NEW_TABLE_SITES . '.site_short,
        ' . NEW_TABLE_SITES . '.site_long,
        ' . TABLE_MEMBER . '.first_name,
        ' . TABLE_MEMBER . '.last_name,
        ' . TABLE_MEMBER . '.business_name,
        ' . TABLE_MEMBER . '.preferred_name,
        ' . TABLE_MEMBER . '.member_id,
        ' . TABLE_MEMBER . '.auth_type,
        ' . NEW_TABLE_BASKETS . '.delivery_type
      FROM
        ' . NEW_TABLE_BASKET_ITEMS . '
      LEFT JOIN ' . NEW_TABLE_PRODUCTS . ' USING(product_id,product_version)
      LEFT JOIN ' . TABLE_PRODUCT_STORAGE_TYPES . ' USING(storage_id)
      LEFT JOIN ' . NEW_TABLE_BASKETS . ' USING(basket_id)
      LEFT JOIN ' . TABLE_MEMBER . ' USING(member_id)
      LEFT JOIN ' . NEW_TABLE_SITES . ' USING(site_id)
      WHERE 
        ' . NEW_TABLE_PRODUCTS . '.producer_id = "' . mysql_real_escape_string($producer_id) . '"
        AND hide_from_invoice = 0
        AND ' . NEW_TABLE_BASKETS . '.delivery_id = ' . $delivery_id . '
      ORDER BY
        ' . NEW_TABLE_SITES . '.site_long,
        ' . NEW_TABLE_PRODUCTS . '.product_name,
        ' . TABLE_MEMBER . '.last_name,
        ' . TABLE_MEMBER . '.business_name,
        ' . TABLE_MEMBER . '.first_name';
    $resultpr = @mysql_query($sqlpr) or die(debug_print("ERROR: 758493 ", array($sqlp, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
    while ($row = mysql_fetch_array($resultpr)) {
        $product_adjust_fee = $row['product_fee_percent'];
        $subcat_adjust_fee = $row['subcategory_fee_percent'];
        $producer_adjust_fee = $row['producer_fee_percent'];
        // Set the coop_markup according to auth_type
        if (in_array('institution', explode(',', $row['auth_type']))) {
            $coop_markup = 1 + $wholesale_markup;
        } else {
            $coop_markup = 1 + $retail_markup;
        }
        // Set the adjust_markup
        $adjust_markup = 1 + $product_adjust_fee + $subcat_adjust_fee + $producer_adjust_fee;
        $product_id = $row['product_id'];
        $product_name = $row['product_name'];
        $customer_notes_to_producer = $row['customer_notes_to_producer'];
        $site_id = $row['site_id'];
        $site_short = $row['site_short'];
        $site_long = $row['site_long'];
        $member_id = $row['member_id'];
        $last_name = $row['last_name'];
        $first_name = $row['first_name'];
        $business_name = $row['business_name'];
        $preferred_name = $row['preferred_name'];
        $delivery_type = $row['delivery_type'];
        $out_of_stock = $row['out_of_stock'];
        $extra_charge = $row['extra_charge'];
        // Set the display_unit_price according to SHOW_ACTUAL_PRICE
        if (SHOW_ACTUAL_PRICE) {
            $unit_price = round($row['item_price'] * $adjust_markup * $coop_markup, 2);
        } else {
            $unit_price = round($row['item_price'] * $adjust_markup, 2);
        }
        $quantity = $row['quantity'];
        $total_weight = $row['total_weight'];
        $ordering_unit = $row['ordering_unit'];
        $pricing_unit = $row['pricing_unit'];
        $storage_code = $row['storage_code'];
        // Figure out how to display the quantity
        $pricing_per_unit = '';
        if ($unit_price != 0) {
            $pricing_per_unit = '$' . number_format($unit_price, 2) . '/' . Inflect::singularize($pricing_unit);
        }
        if ($unit_price != 0 && $extra_charge != 0) {
            $pricing_per_unit .= ' + ';
        }
        if ($extra_charge != 0) {
            $pricing_per_unit .= '$' . number_format($extra_charge, 2) . '/' . Inflect::singularize($ordering_unit);
        }
        if ($out_of_stock == 1) {
            $show_quantity = $quantity;
            $show_unit = '<img src="' . DIR_GRAPHICS . 'checkmark_wht.gif"> ' . Inflect::pluralize_if($show_quantity, $ordering_unit);
            $pricing_per_unit = 'N/A';
            // Clobber the value
        } elseif ($quantity) {
            $show_quantity = $quantity;
            $show_unit = Inflect::pluralize_if($show_quantity, $ordering_unit);
        } elseif ($total_weight) {
            $show_quantity = $total_weight;
            $show_unit = Inflect::pluralize_if($show_quantity, $pricing_unit);
        }
        // Set up primary data structure
        $summary_qty[$site_id][$product_id][$member_id] = $show_quantity;
        // Configure delivery_type to only show when order is a delivery
        if ($delivery_type != 'P') {
            $summary_delivery_type[$member_id] = $delivery_type . '-';
            // Will give something like D-BOISE-117
        } else {
            $summary_delivery_type[$member_id] = '';
            // Will give something like BOISE-117
        }
        $summary_unit[$product_id] = $show_unit;
        $sordering_unit[$product_id] = $pricing_unit;
        $site_subtotal[$site_id][$product_id] += $show_quantity;
        $product_subtotal[$product_id] += $show_quantity;
        // Set up trivial data relationships
        $site_id_2_site[$site_id] = $site_long;
        $site_id_2_site_short[$site_id] = $site_short;
        $product_id_2_product_name[$product_id] = $product_name;
        $product_id_2_storage_code[$product_id] = $storage_code;
        $product_id_2_pricing_per_unit[$product_id][$member_id] = $pricing_per_unit;
        $member_id_2_preferred_name[$member_id] = $preferred_name;
        $customer_notes_2_member_product[$product_id][$member_id] = $customer_notes_to_producer;
    }
    if ($a_address_line1 && $a_address_line2) {
        $a_address = "{$a_address_line1}<br>\n{$a_address_line2}";
    } else {
        $a_address = $a_address_line1 . $a_address_line2;
    }
    $producer_header = '
      <table cellspacing="5">
        <tr>
          <td colspan="2" width="95%"><h3>' . $a_business_name . '</h3></td><td><font size="+1"><strong>Order #' . $delivery_id . ' - ' . $delivery_date . '</strong></font></td>
        </tr>
        <tr>
          <td rowspan="4" width="35%" valign="top">
            ' . $a_address . '<br>
            ' . $a_city . ', ' . $a_state . ' ' . $a_zip . '<br>
            (' . $a_county . ' County)
          </td>
          <td width="15%" align="right"> Email address: </td><td width="45%">' . $a_email_address . '</td></tr>
        <tr><td width="15%" align="right">Home phone: </td><td width="45%">' . $a_home_phone . '</td></tr>
        <tr><td width="15%" align="right">Work phone: </td><td width="45%">' . $a_work_phone . '</td></tr>
        <tr><td width="15%" align="right">Mobile phone: </td><td width="45%">' . $a_mobile_phone . '</td></tr>
      </table><br>';
    if (is_array($summary_qty)) {
        $include_header = true;
        $include_footer = true;
        if ($detail_type == '' || $detail_type == 'customer') {
            $page_links = '
            <a href="' . $_SERVER['SCRIPT_NAME'] . '?detail_type=product">Summary by product</a><br>
            <a href="' . PATH . 'product_list.php?&type=labels_bystoragecustomer">One Label per Customer/Storage</a><br>
            <a href="' . PATH . 'product_list.php?&type=labels_byproduct">One Label per Item</a><br>
            <!--<a href="' . $_SERVER['SCRIPT_NAME'] . '?detail_type=labels">Labels for this order</a><br>
            <a href="configure_labels.php">Configure or select label format</a><br>--><br>
            <h2>Summary for<br>' . $a_business_name . '</h2>
            ';
            $display_page .= '
            <table border="0" cellspacing="0" width="95%">
            ';
            foreach (array_keys($summary_qty) as $site_id) {
                $display_page .= '
                <tr><th colspan="5">&nbsp;</th></tr>
                <tr><th colspan="5" bgcolor="#444444"><font size="+1" color="#ffffff" align="center">' . $site_id_2_site[$site_id] . ' (' . $site_id_2_site_short[$site_id] . ')</font></td></tr>
                <tr><th colspan="5">&nbsp;</th></tr>
                ';
                foreach (array_keys($summary_qty[$site_id]) as $product_id) {
                    $display_page .= '
                    <tr><td colspan="5"><br>' . $a_business_name . ' &ndash; (#' . $product_id . ') ' . $product_id_2_product_name[$product_id] . ' [' . $product_id_2_storage_code[$product_id] . ']</td></tr>
                    ';
                    foreach (array_keys($summary_qty[$site_id][$product_id]) as $member_id) {
                        $quantity = $summary_qty[$site_id][$product_id][$member_id];
                        $display_page .= '
                          <tr><td width="5%">&nbsp;</td>
                          <td width="10%">#' . $member_id . '</td>
                          <td width="40%">' . $member_id_2_preferred_name[$member_id] . '</td>
                          <td width="20%">' . $product_id_2_pricing_per_unit[$product_id][$member_id] . '</td>
                          <td width="20%">(' . $quantity . ') - ' . Inflect::pluralize_if($quantity, $summary_unit[$product_id]) . '<br></td></tr>';
                        if ($customer_notes_2_member_product[$product_id][$member_id]) {
                            $display_page .= '
                              <tr><td width="5%">&nbsp;</td>
                              <td colspan="4" width="90%"><b>Customer Notes: </b>' . $customer_notes_2_member_product[$product_id][$member_id] . '</td></tr>';
                        }
                    }
                    // Delivery Code summary
                    $subtotal = $site_subtotal[$site_id][$product_id];
                    $total = $product_subtotal[$product_id];
                    // Product summary
                    $display_page .= '
                    <tr><td width="5%">&nbsp;</td>
                    <td width="70%" colspan="3" bgcolor="#dddddd">Product quantity (' . $site_id_2_site[$site_id] . '): </td>
                    <td width="20%" bgcolor="#dddddd">(' . $subtotal . ' of ' . $total . ') - ' . Inflect::pluralize_if($total, $summary_unit[$product_id]) . '</td></tr>
                    ';
                }
            }
            //       $display_page .= '<hr width="50%" style="text-align:left;margin:3em 0em 3em;">';
            $display_page .= '</table>';
            if ($use == 'batch') {
                $display_page = $producer_header . $display_page;
            } else {
                $display_page = '</font><div style="font-size:0.9em;">' . $page_links . $producer_header . $display_page . "</div>";
            }
        } elseif ($detail_type == 'product') {
            $include_header = true;
            $include_footer = true;
            $page_links = '
            <a href="' . $_SERVER['SCRIPT_NAME'] . '?detail_type=customer">Summary by customer</a><br>
            <a href="' . PATH . 'product_list.php?&type=labels_bystoragecustomer">One Label per Customer/Storage</a><br>
            <a href="' . PATH . 'product_list.php?&type=labels_byproduct">One Label per Item</a><br>
            <!--<a href="' . $_SERVER['SCRIPT_NAME'] . '?detail_type=labels">Labels for this order</a><br>
            <a href="configure_labels.php">Configure or select label format</a><br>--><br>
            <h2>Overall Product Summary for<br>' . $a_business_name . '</h2>
            ';
            foreach (array_keys($product_id_2_storage_code) as $product_id) {
                // Delivery Code summary
                $total = $product_subtotal[$product_id];
                $unit = $summary_unit[$product_id];
                // Product summary
                $display_page .= '<div style="width:40em;float:left;">' . $product_id_2_product_name[$product_id] . ' (#' . $product_id . ') [' . $product_id_2_storage_code[$product_id] . ']</div><div style="width:10em;float:left;">(' . $total . ') - ' . Inflect::pluralize_if($total, $unit) . '</div><br>';
            }
            if ($use == 'batch') {
                $display_page = $producer_header . $display_page;
            } else {
                $display_page = '</font><div style="font-size:0.9em;">' . $page_links . $producer_header . $display_page . '</div>';
            }
        } elseif ($detail_type == 'labels') {
            require_once "../func/label_config.class.php";
            // Choose the labels that were selected from configure_labels.php
            $label_name = $_SESSION['label_select'];
            // Set up the label based on stored cookie label values
            $current_label = output_Label::cookieToLabel($label_name);
            if ($label_name) {
                // If a printer has been chosen, then include label styles
                $label_sheet_styles .= '
                  .container {
                    overflow:hidden;
                    width:100%;
                    height:100%
                    }
                  ' . $current_label->getLabelCSS();
                // Set up font scaling
                $font_scaling = $current_label->font_scaling;
                if (!$font_scaling) {
                    $font_scaling = 1.0;
                }
                $font_scaling_link = '';
                // Scaling is automatic, so not controls are given
            } else {
                // Otherwise include a simple spacer style between labels
                $label_sheet_styles .= '
                  .container {
                    margin-bottom: 3em;
                    }
                  a {
                    text-decoration: none;
                    color:#880088;
                    }
                  a:hover {
                    text-decoration: underline;
                    color:#0000ff;
                    }
                  ';
                // Set up font scaling
                $font_scaling = $_GET['font_scaling'];
                if (!$font_scaling) {
                    $font_scaling = 1.0;
                }
                if ($font_scaling < 0.3) {
                    $font_scaling = 0.3;
                }
                if ($font_scaling > 4.0) {
                    $font_scaling = 4.0;
                }
                // Controls for scaling the label
                $font_scaling_link = '<!-- A custom label-sheet is NOT selected.<br>
                  Click <a href="configure_labels.php">here</a> to configure custom labels (i.e. Avery labels)<br> -->
                  Change label size: 
                  [<a href="' . $_SERVER['SCRIPT_NAME'] . '?detail_type=labels&font_scaling=' . ($font_scaling - 0.1) . '">Smaller</a>]
                  [<a href="' . $_SERVER['SCRIPT_NAME'] . '?detail_type=labels&font_scaling=' . ($font_scaling + 0.1) . '">Larger</a>]
                  <br><br><br>';
            }
            // Include the header and styles for this particular application
            $label_sheet .= '
              <head>
              <style>
              .counter {
                float:left;
                font-size:' . number_format(3 * $font_scaling, 2) . 'em;
                font-weight:bold;
                }
              .site {
                font-size:' . number_format(1.2 * $font_scaling, 2) . 'em;
                font-weight:bold;
                }
              .customer {
                font-size:' . number_format(1.0 * $font_scaling, 2) . 'em;
                }
              .producer {
                font-size:' . number_format(1.0 * $font_scaling, 2) . 'em;
                }
              .product {
                font-size:' . number_format(0.9 * $font_scaling, 2) . 'em;
                font-style:italic;
                line-height:100%;
                }
              ' . $label_sheet_styles;
            // Close the header and open the body
            $label_sheet .= '
              </style>
              </head>
              <body>' . $font_scaling_link;
            // Begin the label sheet content
            $label_sheet .= $current_label->beginLabelSheet();
            foreach (array_keys($product_id_2_product_name) as $product_id) {
                foreach (array_keys($summary_qty) as $site_id) {
                    if (is_array($summary_qty[$site_id][$product_id])) {
                        foreach (array_keys($summary_qty[$site_id][$product_id]) as $member_id) {
                            $quantity = $summary_qty[$site_id][$product_id][$member_id];
                            $delivery_type = $summary_delivery_type[$member_id];
                            $unit = $summary_unit[$product_id];
                            $label_sheet .= '
                              <div class="container">
                              <div class="site">' . $delivery_type . $site_id . '-' . $member_id . '[' . $product_id_2_storage_code[$product_id] . ']</div>
                              <div class="customer">' . $member_id_2_preferred_name[$member_id] . '</div>
                              <div class="producer">' . $a_business_name . '</div>
                              <div class="product">(' . $quantity . ') - ' . Inflect::pluralize_if($quantity, $summary_unit[$product_id]) . $product_id_2_product_name[$product_id] . ' (#' . $product_id . ')</div>
                              </div>';
                            $label_sheet .= $current_label->advanceLabel();
                        }
                    }
                }
            }
            $label_sheet .= $current_label->finishLabelSheet();
            // Finally, just before printing, clear the $_SESSION['label_select']
            // variable so the next use of this function will require choosing a
            // label type again.
            //    unset ($_SESSION['label_select']);
            $display_page .= $label_sheet;
        }
    } else {
        $include_header = true;
        $include_footer = true;
        $display_page .= "</font>";
        $display_page .= '<div style="font-size:0.9em;">';
        $display_page .= "<h2>No products to report</h2><br>\n";
        $display_page .= '</div>';
    }
    return $display_page;
}
function pricing_display_calc($data)
{
    if ($data['display_retail_price'] && $data['display_unit_retail_price']) {
        $pricing_display_calc .= '
          <span class="retail">' . ($_GET['type'] == 'producer_list' ? 'Retail: ' : '') . '$' . number_format(round($data['display_unit_retail_price'], 2), 2) . '/' . Inflect::singularize($data['pricing_unit']) . '</span>';
    }
    if ($data['display_wholesale_price'] && $data['display_unit_wholesale_price']) {
        $pricing_display_calc .= '
          <span class="whsle">' . ($_GET['type'] == 'producer_list' ? 'Whsle: ' : '') . '$' . number_format($data['display_unit_wholesale_price'], 2) . '/' . Inflect::singularize($data['pricing_unit']) . '</span>';
    }
    if (($data['display_wholesale_price'] && $data['display_unit_wholesale_price'] || $data['display_retail_price'] && $data['display_unit_retail_price']) && $data['extra_charge'] != 0) {
        //         $pricing_display_calc .= '
        //           <br>and<br>';
    }
    if ($data['extra_charge'] != 0) {
        $pricing_display_calc .= '
          <span class="extra">' . ($data['extra_charge'] > 0 ? '' : '-&nbsp;') . '$' . number_format(abs(round($data['extra_charge'], 2)), 2) . '/' . Inflect::singularize($data['ordering_unit']) . '</span>';
    }
    return $pricing_display_calc;
}
Example #11
0
    public static function RelatedTypeInterface($customField, $inputName, $groupCounter, $fieldCounter)
    {
        global $mf_domain, $wpdb;
        $mf_post_id = apply_filters('mf_source_post_data', @$_REQUEST['post']);
        $customFieldId = '';
        if (isset($mf_post_id)) {
            $customFieldId = $customField->id;
            $value = esc_attr(RCCWP_CustomField::GetCustomFieldValues(true, $mf_post_id, $customField->name, $groupCounter, $fieldCounter));
        } else {
            $value = $customField->default_value[0];
        }
        //get id of related type / panel
        $panel_id = (int) $customField->properties['panel_id'];
        $requiredClass = "";
        if ($customField->required_field) {
            $requiredClass = "field_required";
        }
        ?>
		<div class="mf_custom_field">
		<select tabindex="3" <?php 
        if ($customField->required_field) {
            echo 'validate="required:true"';
        }
        ?>
 class="<?php 
        echo $requiredClass;
        ?>
 listbox_mf" name="<?php 
        echo $inputName;
        ?>
">
			<option value=""><?php 
        _e('--Select--', $mf_domain);
        ?>
</option>
		
		<?php 
        $pn_cache = array();
        // setup a panel name cache (so we only look up the panel name ONCe for each panel ID)
        if ($panel_id == -4) {
            $options = get_posts("post_type=post&numberposts=-1&order=ASC&orderby=title");
        } elseif ($panel_id == -3) {
            $options = get_posts("post_type=page&numberposts=-1&order=ASC&orderby=title");
        } elseif ($panel_id == -2) {
            $options = get_posts("post_type=post&meta_key=_mf_write_panel_id&numberposts=-1&order=ASC&orderby=title");
        } elseif ($panel_id == -1) {
            $options = get_posts("post_type=page&meta_key=_mf_write_panel_id&numberposts=-1&order=ASC&orderby=title");
        } elseif ($panel_id == -6) {
            $options = get_posts("post_type=any&numberposts=-1");
        } elseif ($panel_id == -7) {
            $options = get_categories("hide_empty=0");
            $options = RCCWP_WritePostPage::mf_category_order($options, 0, 0);
        } elseif ($panel_id == -5) {
            remove_filter('posts_where', array('RCCWP_Query', 'ExcludeWritepanelsPosts'));
            add_filter('posts_fields', 'RelatedTypeFieldsFilter');
            add_filter('posts_orderby', 'RelatedTypeOrderByFilter');
            $options = get_posts(array('suppress_filters' => false, 'post_type' => 'any', 'meta_key' => '_mf_write_panel_id', 'nopaging' => true, 'order' => 'ASC'));
            remove_filter('posts_fields', 'RelatedTypeFieldsFilter');
            remove_filter('posts_orderby', 'RelatedTypeOrderByFilter');
            add_filter('posts_where', array('RCCWP_Query', 'ExcludeWritepanelsPosts'));
        } else {
            $options = get_posts("post_type=any&meta_key=_mf_write_panel_id&numberposts=-1&meta_value={$panel_id}&order=ASC&orderby=title");
        }
        $last_panel_name = "";
        // traversal (for grouping)
        foreach ($options as $option) {
            /* TRAVERSAL ADDITION - Adds grouping of related type fields when all write panels are listed -- */
            $panel_name = "";
            $display_panel_name = "";
            if ($panel_id == -5 || $panel_id == -2 || $panel_id == -1) {
                $panel_name = $pn_cache[$option->meta_value];
                if (!$panel_name) {
                    // look it up
                    $sql = $wpdb->prepare("SELECT name FROM " . MF_TABLE_PANELS . " WHERE id = %d", array($option->meta_value));
                    $panel_name = $wpdb->get_var($sql);
                    if ($panel_name) {
                        $pn_cache[$option->meta_value] = $panel_name;
                    }
                }
                $panel = RCCWP_CustomWritePanel::Get($option->meta_value);
                if (!$panel_name) {
                    $panel_name = "";
                    $display_panel_name = "";
                } else {
                    if ($panel->single) {
                        $display_panel_name = "";
                    } else {
                        $display_panel_name = "&nbsp;&nbsp;&nbsp;" . Inflect::singularize($panel_name) . " - ";
                    }
                }
                if ($panel_name != "" && $panel_name != $last_panel_name) {
                    if ($last_panel_name != "") {
                        echo "</optgroup>";
                    }
                    if ($panel->single) {
                        $last_panel_name = "";
                    } else {
                        echo '<optgroup label="' . Inflect::pluralize($panel_name) . '">';
                        $last_panel_name = $panel_name;
                    }
                }
            }
            /* END TRAVERSAL ADDITION */
            if ($panel_id == -7) {
                $selected = $option->term_id == $value ? 'selected="selected"' : '';
                ?>
                    <option value="<?php 
                echo $option->term_id;
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo $display_panel_name . $option->name;
                ?>
</option><!-- TRAVERSAL UPDATE, adds display panel name as prefix -->
                       <?php 
            } else {
                $selected = $option->ID == $value ? 'selected="selected"' : '';
                ?>
                    <option value="<?php 
                echo $option->ID;
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo $display_panel_name . $option->post_title;
                ?>
</option><!-- TRAVERSAL UPDATE, adds display panel name as prefix -->
                       <?php 
            }
        }
        // TRAVERSAL ADDITION, closes optgroup
        if ($last_panel_name != "") {
            echo "</optgroup>";
        }
        // END TRAVERSAL ADDITION
        ?>

		</select></div>
		<?php 
        if ($customField->required_field) {
            ?>
			<div class="mf_message_error"><label for="<?php 
            echo $inputName;
            ?>
" class="error_magicfields error"><?php 
            _e("This field is required", $mf_domain);
            ?>
</label></div>
		<?php 
        }
        ?>
		
		<?php 
    }
Example #12
0
 /**
  * has_many()
  * 
  * Prepare a has_many association to another model type (Multiple records of another given model contain a foreign key for this model)
  * 
  * @param string $classes Class of the associated model (plural)
  * @param array $options Standard association options (see above)
  *
  * @return void
  **/
 public function has_many($classes, $options = array())
 {
     if ($this->config->associable) {
         $I = new Inflect();
         $class = $I->singularize($classes);
         $classes = $I->pluralize($class);
         if (is_null($this->id)) {
             $this->config->associations_waiting['id'][] = array('type' => 'has_many', 'class' => $classes, 'options' => $options);
         } else {
             $class_name = $this->classify($class);
             $c = new $class_name();
             if (isset($options['as'])) {
                 $classes = $options['as'];
             }
             if (isset($options['field'])) {
                 $id_field = $options['field'];
             } else {
                 $id_field = strtolower(get_class($this)) . '_id';
             }
             $find_options = array();
             if (isset($options['index'])) {
                 $find_options['index'] = $options['index'];
             }
             $members = $c->find(array("`{$id_field}` = '{$this->id}'"), array('associable' => false), $find_options);
             $this->{$classes} = $members;
             array_push($this->config->ignore, $class);
         }
     }
 }
    function Edit()
    {
        global $FIELD_TYPES;
        global $mf_domain;
        $custom_field = RCCWP_CustomField::Get((int) $_GET['custom-field-id']);
        $customGroupID = $custom_field->group_id;
        if (isset($customGroupID)) {
            $group = RCCWP_CustomGroup::Get($customGroupID);
            ?>
      
      <script type="text/javascript">
      
      var mf_create_field = false;
        
      var mf_group_info = {
        'name' : '<?php 
            echo stripslashes($group->name);
            ?>
',
        'safe_name' : '<?php 
            echo sanitize_title_with_dashes($group->name);
            ?>
',
        'singular_safe_name' : '<?php 
            echo sanitize_title_with_dashes(Inflect::singularize($group->name));
            ?>
'
      };
      
      </script>
      
      <?php 
        }
        if (in_array($custom_field->type, array('Image'))) {
            $cssVlaue = $custom_field->CSS;
        }
        ?>
	  	
  		<div class="wrap">
  		<h2><?php 
        _e('Edit Custom Field', $mf_domain);
        ?>
 - <em><?php 
        echo $custom_field->description;
        ?>
</em> <?php 
        if ($group && $group->name != "__default") {
            _e("In Group", $mf_domain);
            echo " <em>" . $group->name . "</em>";
        }
        ?>
</h2>
  		
  		<br class="clear" />
  		<?php 
        if (isset($_GET['err_msg'])) {
            switch ($_GET['err_msg']) {
                case -1:
                    ?>
				<div class="error"><p> <?php 
                    _e('A field with the same name already exists in this write panel. Please choose a different name.', $mf_domain);
                    ?>
</p></div>
				<?php 
            }
        }
        ?>
  		
	  	
  		<form action="<?php 
        echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('submit-edit-custom-field') . "&custom-group-id={$customGroupID}";
        ?>
" method="post" id="edit-custom-field-form"  onsubmit="return checkEmpty();">
  		<input type="hidden" name="custom-field-id" value="<?php 
        echo $custom_field->id;
        ?>
">
		
		
		<table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
		<tbody>
		<tr valign="top">
			<th scope="row"><?php 
        _e('Label', $mf_domain);
        ?>
:</th>
			<td><input name="custom-field-description" id="custom-field-description" size="40" type="text" value="<?php 
        echo htmlspecialchars($custom_field->description);
        ?>
" /></td>
		</tr>
		<tr valign="top">
			<th scope="row"><?php 
        _e('Name', $mf_domain);
        ?>
:</th>
			<td><input name="custom-field-name" id="custom-field-name" size="40" type="text" value="<?php 
        echo htmlspecialchars($custom_field->name);
        ?>
" /><button id="bt-custom-field-name-suggest" class="button">Suggest</button></td>
		</tr>
		<tr valign="top">
			<th scope="row"><?php 
        _e('Help text', $mf_domain);
        ?>
:</th>
			<td><input name="custom-field-helptext" id="custom-field-helptext" size="40" type="text" value="<?php 
        echo htmlspecialchars($custom_field->help_text);
        ?>
" /><br/><small><?php 
        _e('If set, this will be displayed in a tooltip next to the field label', $mf_domain);
        ?>
</small></td>
		</tr>
		<tr valign="top">
			<th scope="row"><?php 
        _e('Can be duplicated', $mf_domain);
        ?>
:</th>
			<td><input name="custom-field-duplicate" id="custom-field-duplicate" type="checkbox" value="1" <?php 
        echo $custom_field->duplicate == 0 ? "" : "checked";
        ?>
/></td>
		</tr>
		<tr valign="top">
			<th scope="row"><?php 
        _e('Order', $mf_domain);
        ?>
:</th>
			<td>
				<input name="custom-field-order" id="custom-field-order" size="2" type="text" value="<?php 
        echo $custom_field->display_order;
        ?>
" />
			</td>	
		</tr>
		<?php 
        if (in_array($custom_field->type_id, array($FIELD_TYPES['textbox'], $FIELD_TYPES['multiline_textbox'], $FIELD_TYPES['checkbox'], $FIELD_TYPES['checkbox_list'], $FIELD_TYPES['radiobutton_list'], $FIELD_TYPES['dropdown_list'], $FIELD_TYPES['listbox'], $FIELD_TYPES['file'], $FIELD_TYPES['image'], $FIELD_TYPES['audio'], $FIELD_TYPES['related_type'], $FIELD_TYPES['Image (Upload Media)'], $FIELD_TYPES['markdown_textbox']))) {
            ?>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Required', $mf_domain);
            ?>
:</th>
			<td>
				<select name="custom-field-required" id="custom-field-required">
					<option value="0" <?php 
            echo $custom_field->required_field == 0 ? 'selected="selected"' : '';
            ?>
 ><?php 
            _e('Not Required - can be empty', $mf_domain);
            ?>
</option>
					<option value="1" <?php 
            echo $custom_field->required_field == 1 ? 'selected="selected"' : '';
            ?>
 ><?php 
            _e('Required - can not be empty', $mf_domain);
            ?>
</option>
				</select>
			</td>	
		</tr>

		
		<?php 
        }
        ?>
		<?php 
        if (in_array($custom_field->type, array('Textbox', 'Listbox'))) {
            ?>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Size', $mf_domain);
            ?>
:</th>
			<td><input type="text" name="custom-field-size" id="custom-field-size" size="2" value="<?php 
            echo $custom_field->properties['size'];
            ?>
" /></td>
		</tr>	
		<?php 
        }
        ?>

		<?php 
        if (in_array($custom_field->type, array('Multiline Textbox'))) {
            ?>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Height', $mf_domain);
            ?>
:</th>
			<td><input type="text" name="custom-field-height" id="custom-field-height" size="2" value="<?php 
            echo $custom_field->properties['height'];
            ?>
" /></td>
		</tr>	
		<tr valign="top">
			<th scope="row"><?php 
            _e('Width', $mf_domain);
            ?>
:</th>
			<td><input type="text" name="custom-field-width" id="custom-field-width" size="2" value="<?php 
            echo $custom_field->properties['width'];
            ?>
" /></td>
		</tr>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Hide Visual Editor for this field', $mf_domain);
            ?>
:</th>
			<td><input name="hide-visual-editor" id="hide-visual-editor" value="1" type="checkbox" <?php 
            echo $custom_field->properties['hide-visual-editor'] == 0 ? "" : "checked";
            ?>
 ></td>
		</tr>	
		<?php 
        }
        ?>
		<?php 
        if (in_array($custom_field->type_id, array($FIELD_TYPES['textbox'], $FIELD_TYPES['multiline_textbox']))) {
            ?>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Evaluate Max Length', $mf_domain);
            ?>
:</th>
			<td><input name="strict-max-length" id="strict-max-length" value="1" type="checkbox" <?php 
            echo $custom_field->properties['strict-max-length'] == 0 ? "" : "checked";
            ?>
 ><br/><small><?php 
            _e('If set, Hide Visual Editor for this field', $mf_domain);
            ?>
</small></td>
		</tr>
		<?php 
        }
        ?>

		<?php 
        if (in_array($custom_field->type, array('Date'))) {
            ?>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Format', $mf_domain);
            ?>
:</th>
			<td>
				<select name="custom-field-date-format" id="custom-field-date-format">
					<option value="m/d/Y" <?php 
            if ($custom_field->properties['format'] == "m/d/Y") {
                echo " selected ";
            }
            ?>
>4/20/2008</option>
					<option value="l, F d, Y" <?php 
            if ($custom_field->properties['format'] == "l, F d, Y") {
                echo " selected ";
            }
            ?>
>Sunday, April 20, 2008</option>
					<option value="F d, Y" <?php 
            if ($custom_field->properties['format'] == "F d, Y") {
                echo " selected ";
            }
            ?>
>April 20, 2008</option>
					<option value="m/d/y" <?php 
            if ($custom_field->properties['format'] == "m/d/y") {
                echo " selected ";
            }
            ?>
>4/20/08</option>
					<option value="Y-m-d" <?php 
            if ($custom_field->properties['format'] == "Y-m-d") {
                echo " selected ";
            }
            ?>
>2008-04-20</option>
					<option value="d-M-y" <?php 
            if ($custom_field->properties['format'] == "d-M-y") {
                echo " selected ";
            }
            ?>
>20-Apr-08</option>
					<option value="m.d.Y" <?php 
            if ($custom_field->properties['format'] == "m.d.Y") {
                echo " selected ";
            }
            ?>
>4.20.2008</option>
					<option value="m.d.y" <?php 
            if ($custom_field->properties['format'] == "m.d.y") {
                echo " selected ";
            }
            ?>
>4.20.08</option>
				</select>
			</td>
		</tr>	
		<?php 
        }
        ?>
		
		<?php 
        if (in_array($custom_field->type, array('Slider'))) {
            ?>
	
		<tr valign="top">
			<th scope="row"><?php 
            echo _e('Value min', $mf_domain);
            ?>
:</th>
			<td><input type="text" name="custom-field-slider-min" id="custom-field-slider-min" size="2" value="<?php 
            echo $custom_field->properties['min'];
            ?>
" /></td>
		</tr>
		<tr valign="top">
			<th scope="row"><?php 
            echo _e('Value max', $mf_domain);
            ?>
:</th>
			<td><input type="text" name="custom-field-slider-max" id="custom-field-slider-max" size="2" value="<?php 
            echo $custom_field->properties['max'];
            ?>
" /></td>
		</tr>		
		<tr valign="top">
			<th scope="row"><?php 
            echo _e('Stepping', $mf_domain);
            ?>
:</th>
			<td><input type="text" name="custom-field-slider-step" id="custom-field-slider-step" size="2" value="<?php 
            echo $custom_field->properties['step'];
            ?>
" /></td>
		</tr>
		<?php 
        }
        ?>

		<?php 
        //eeble
        if (in_array($custom_field->type, array('Related Type'))) {
            $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
            ?>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Related Type Panel', $mf_domain);
            ?>
:</th>
			<td><select name="custom-field-related-type-panel-id" id="custom-field-related-type-panel-id">
                                <option value="-7" <?php 
            if ($custom_field->properties['panel_id'] == -7) {
                echo 'selected';
            }
            ?>
 >All Categories</option>
				<option value="-6" <?php 
            if ($custom_field->properties['panel_id'] == -6) {
                echo 'selected';
            }
            ?>
 >All Posts and Pages</option>
				<option value="-5" <?php 
            if ($custom_field->properties['panel_id'] == -5) {
                echo 'selected';
            }
            ?>
 >All Posts and Pages with Write Panel</option>
				<option value="-4" <?php 
            if ($custom_field->properties['panel_id'] == -4) {
                echo 'selected';
            }
            ?>
 >All Post</option>
				<option value="-3" <?php 
            if ($custom_field->properties['panel_id'] == -3) {
                echo 'selected';
            }
            ?>
 >All Page</option>
				<option value="-2" <?php 
            if ($custom_field->properties['panel_id'] == -2) {
                echo 'selected';
            }
            ?>
 >All Post with Write Panel</option>
				<option value="-1" <?php 
            if ($custom_field->properties['panel_id'] == -1) {
                echo 'selected';
            }
            ?>
 >All Page with Write Panel</option>
				<?php 
            foreach ($customWritePanels as $panel) {
                ?>
					<option value="<?php 
                echo $panel->id;
                ?>
" <?php 
                if ($custom_field->properties['panel_id'] == $panel->id) {
                    echo 'selected';
                }
                ?>
><?php 
                echo $panel->name;
                ?>
</option>
				<?php 
            }
            ?>
			</select></td>
		</tr>
		<?php 
        }
        ?>

		<?php 
        if ($custom_field->has_options == "true") {
            $options = implode("\n", (array) $custom_field->options);
            ?>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Options', $mf_domain);
            ?>
:</th>
			<td>
				<textarea name="custom-field-options" id="custom-field-options" rows="2" cols="38"><?php 
            echo htmlspecialchars($options);
            ?>
</textarea><br />
				<em><?php 
            _e('Separate each option with a newline.', $mf_domain);
            ?>
</em>
			</td>
		</tr>
		<tr valign="top">
			<th scope="row"><?php 
            _e('Default Value', $mf_domain);
            ?>
:</th>
			<td>
				<?php 
            $default_value = implode("\n", (array) $custom_field->default_value);
            if ($custom_field->allow_multiple_values == "true") {
                ?>
				<textarea name="custom-field-default-value" id="custom-field-default-value" rows="2" cols="38"><?php 
                echo htmlspecialchars($default_value);
                ?>
</textarea><br />
				<em><?php 
                _e('Separate each value with a newline.', $mf_domain);
                ?>
</em>
				<?php 
            } else {
                ?>
				<input type="text" name="custom-field-default-value" id="custom-field-default-value" size="25" value="<?php 
                echo htmlspecialchars($default_value);
                ?>
" />
				<?php 
            }
            ?>
			</td>
		</tr>
		<?php 
        }
        ?>
		<tr valign="top">
			<th scope="row"><?php 
        _e('Type', $mf_domain);
        ?>
:</th>
			<td>

				<!-- START :: Javascript for Image/Photo' Css Class -->
				<script type="text/javascript" language="javascript">
					submitForm = false;
					function fun(name)
					{
						if(name == "Image")
						{
							document.getElementById('divCSS').style.display = 'inline';
							document.getElementById('divLbl').style.display = 'inline';
							document.getElementById('lblHeight').style.display = 'inline';
							document.getElementById('txtHeight').style.display = 'inline';
							document.getElementById('lblWidth').style.display = 'inline';
							document.getElementById('txtWidth').style.display = 'inline';
						}
						else
						{
							document.getElementById('divCSS').style.display = 'none';
							document.getElementById('divLbl').style.display = 'none';
							document.getElementById('lblHeight').style.display = 'none';
							document.getElementById('txtHeight').style.display = 'none';
							document.getElementById('lblWidth').style.display = 'none';
							document.getElementById('txtWidth').style.display = 'none';
						}
					}
					function checkEmpty()
					{
						if (submitForm && (document.getElementById('custom-field-name').value == "" || document.getElementById('custom-field-description').value == "")){
							alert("<?php 
        _e('Please fill in the name and the label of the field', $mf_domain);
        ?>
");	
							return false;
						}
						return true;
						
					}
				</script>
				<!-- END :: Javascript for Image/Photo' Css Class -->

				<?php 
        $field_types = RCCWP_CustomField::GetCustomFieldTypes();
        foreach ($field_types as $field) {
            $checked = $field->name == $custom_field->type ? 'checked="checked"' : '';
            ?>
					<label><input name="custom-field-type" value="<?php 
            echo $field->id;
            ?>
" type="radio" <?php 
            echo $checked;
            ?>
 onclick='fun("<?php 
            echo $field->name;
            ?>
");'/>
					<?php 
            echo $field->name;
            ?>
</label><br />
				<?php 
        }
        ?>
			</td>
		</tr>
		<!-- START :: For Image/Photo' Css -->
		<?php 
        if ($custom_field->type == "Image" || $custom_field->type == "Image (Upload Media)") {
            $h = $w = $c = NULL;
            if ($custom_field->type == "Image") {
                $isDisplay = $custom_field->type == "Image" ? 'display:inline;' : 'display:none;';
            }
            if ($custom_field->type == "Image (Upload Media)") {
                $isDisplay = $custom_field->type == "Image (Upload Media)" ? 'display:inline;' : 'display:none;';
            }
            if (isset($custom_field->properties['params'])) {
                preg_match('/w\\=[0-9]+/', $custom_field->properties['params'], $match_w);
                if ($match_w) {
                    $w = str_replace("w=", '', $match_w[0]);
                    $custom_field->properties['params'] = str_replace("&" . $match_w[0], "", $custom_field->properties['params']);
                }
                preg_match('/h\\=[0-9]+/', $custom_field->properties['params'], $match_h);
                if ($match_h) {
                    $h = str_replace("h=", '', $match_h[0]);
                    $custom_field->properties['params'] = str_replace("&" . $match_h[0], "", $custom_field->properties['params']);
                }
                if ($custom_field->properties['params']) {
                    if (substr($custom_field->properties['params'], 0, 1) == "&") {
                        $c = substr($custom_field->properties['params'], 1);
                    }
                }
            }
            $cssVlaue = $custom_field->CSS;
            ?>
		<tr valign="top">
			<th scope="row"><span id="lblHeight" style="<?php 
            echo $isDisplay;
            ?>
"><?php 
            _e('Max Height', $mf_domain);
            ?>
:</span></th>
			<td><span id="txtHeight" style="<?php 
            echo $isDisplay;
            ?>
"><input type="text" name="custom-field-photo-height" id="custom-field-photo-height" size="3" value="<?php 
            echo $h;
            ?>
" /></span></td>
		</tr>	
		<tr valign="top">
			<th scope="row"><span id="lblWidth" style="<?php 
            echo $isDisplay;
            ?>
"><?php 
            _e('Max Width', $mf_domain);
            ?>
:</span></th>
			<td><span id="txtWidth" style="<?php 
            echo $isDisplay;
            ?>
"><input type="text" name="custom-field-photo-width" id="custom-field-photo-width" size="3" value="<?php 
            echo $w;
            ?>
" /></span></td>
		</tr>
		<tr valign="top">
			<th scope="row"><span id="lblWidth" style="<?php 
            echo $isDisplay;
            ?>
"><?php 
            _e('Custom', $mf_domain);
            ?>
:</span></th>
			<td><span id="txtWidth" style="<?php 
            echo $isDisplay;
            ?>
"><input type="text" name="custom-field-custom-params" id="custom-field-custom-params" value="<?php 
            echo $c;
            ?>
" /></span>
		
		</td>
		</tr>
		
		<tr valign="top">
			<th scope="row"><div id="divLbl" style="<?php 
            echo $isDisplay;
            ?>
"><?php 
            _e('Css Class', $mf_domain);
            ?>
:</div></th>
			<td>
				<div id="divCSS" style="<?php 
            echo $isDisplay;
            ?>
">
				<input name="custom-field-css" id="custom-field-css" size="40" type="text" value="<?php 
            echo $cssVlaue;
            ?>
" />
				</div>
			</td>
		</tr>
    <?php 
        }
        ?>
		<!-- END :: For Image/Photo' Css -->		
		</tbody>
		</table>
		
		<input name="mf_action" type="hidden" value="submit-edit-custom-field" />
  		<p class="submit" >
  			<a style="color:black" href="<?php 
        echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('cancel-create-custom-field') . "&custom-group-id={$customGroupID}";
        ?>
" class="button"><?php 
        _e('Cancel', $mf_domain);
        ?>
</a> 
  			<input type="submit" id="submit-edit-custom-field" value="<?php 
        _e('Update', $mf_domain);
        ?>
" onclick="submitForm=true;" />
  		</p>
	  	
  		</form>
	  	
  		</div>
	  	
  		<?php 
    }
Example #14
0
 protected function get_model_name()
 {
     return Inflect::singularize($this->getRequest()->getControllerName()) . "Model";
 }
    public static function Main()
    {
        global $FIELD_TYPES, $mf_domain;
        $customGroupID = $_REQUEST['custom-group-id'];
        if (isset($customGroupID)) {
            $group = RCCWP_CustomGroup::Get($customGroupID);
            ?>

      <script type="text/javascript">

      var mf_create_field = true;

      var mf_group_info = {
        'name' : '<?php 
            echo stripslashes($group->name);
            ?>
',
        'safe_name' : '<?php 
            echo sanitize_title_with_dashes($group->name);
            ?>
',
        'singular_safe_name' : '<?php 
            echo sanitize_title_with_dashes(Inflect::singularize($group->name));
            ?>
'
      };

      </script>

      <?php 
        }
        ?>


  		<div class="wrap">

  		<h2><?php 
        _e("Create Custom Field", $mf_domain);
        ?>
 <?php 
        if ($group && $group->name != "__default") {
            _e("In Group", $mf_domain);
            echo " <em>" . $group->name . "</em>";
        }
        ?>
</h2>
  		<br class="clear" />
  		<?php 
        if (isset($_GET['err_msg'])) {
            switch ($_GET['err_msg']) {
                case -1:
                    ?>
				<div class="error"><p> <?php 
                    _e('A field with the same name already exists in this write panel. Please choose a different name.', $mf_domain);
                    ?>
</p></div>
				<?php 
            }
        }
        ?>

  	<form action="<?php 
        echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('continue-create-custom-field');
        ?>
" method="post" name="create_custom_field_form" id="create-custom-field-form" onsubmit="return checkEmpty();" autocomplete="off">

  		<?php 
        wp_nonce_field('continue-create-custom-field');
        ?>

		<?php 
        if (isset($_GET['custom-group-id']) && !empty($_GET['custom-group-id'])) {
            ?>
  			<input type="hidden" name="custom-group-id" value="<?php 
            echo $_GET['custom-group-id'];
            ?>
">
		<?php 
        }
        ?>
		<?php 
        if (isset($_POST['custom-group-id']) && !empty($_POST['custom-group-id'])) {
            ?>
  			<input type="hidden" name="custom-group-id" value="<?php 
            echo $_POST['custom-group-id'];
            ?>
">
		<?php 
        }
        ?>


		<table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
		<tbody>

		<tr valign="top">
			<th scope="row"><?php 
        _e("Label", $mf_domain);
        ?>
:</th>
			<td>
				<input name="custom-field-description" id="custom-field-description" size="40" type="text" />
				<p>
					<?php 
        _e('Type a label for the field. The label of the field is displayed
					beside the field in Write Panel page.', $mf_domain);
        ?>
				</p>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><?php 
        _e("Name", $mf_domain);
        ?>
:</th>
			<td>
				<input name="custom-field-name" id="custom-field-name" size="40" type="text" />
				<input type="hidden" id="custom-field-name_hidden" name="custom-field-name_hidden" onchange="copyField();" />

				<p>
					<?php 
        _e('Type a unique name for the field, the name must be unique among all fields
					in this panel. The name of the field is the key by which you can retrieve
					the field value later.', $mf_domain);
        ?>

				</p>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><?php 
        _e('Help text', $mf_domain);
        ?>
:</th>
			<td>
				<input name="custom-field-helptext" id="custom-field-helptext" size="40" type="text" /><br/><small><?php 
        _e('If set, this will be displayed in a tooltip next to the field label', $mf_domain);
        ?>
</small></td>
		</tr>

		<tr valign="top">
			<th scope="row"><?php 
        _e("Can be duplicated", $mf_domain);
        ?>
:</th>
			<td><input name="custom-field-duplicate" id="custom-field-duplicate" type="checkbox" value="1" /></td>
		</tr>

		<tr valign="top">
			<th scope="row"><?php 
        _e("Order", $mf_domain);
        ?>
:</th>
			<td><input type="text" name="custom-field-order" id="custom-field-order" size="2" value="0" /></td>
		</tr>


		<tr valign="top">
			<th scope="row"><?php 
        _e("Required", $mf_domain);
        ?>
:</th>
			<td>
				<select name="custom-field-required" id="custom-field-required">
					<option value="0" selected="selected"><?php 
        _e('Not Required - can be empty', $mf_domain);
        ?>
</option>
					<option value="1"><?php 
        _e('Required - can not be empty', $mf_domain);
        ?>
</option>
				</select>
			</td>
		</tr>

		<tr valign="top">
			<th scope="row"><?php 
        _e("Type", $mf_domain);
        ?>
:</th>
			<td>

				<!-- START :: Javascript for Image/Photo' Css Class and for check -->
				<script type="text/javascript" language="javascript">
					submitForm = false;
					function fun(name)
					{
						if(name == "Image" || name == 'Image (Upload Media)')
						{
							document.getElementById('divLbl').style.display = 'inline';
							document.getElementById('divCSS').style.display = 'inline';
						}
						else
						{
							document.getElementById('divLbl').style.display = 'none';
							document.getElementById('divCSS').style.display = 'none';
						}
					}

					function checkEmpty()
					{
						if (submitForm && (document.getElementById('custom-field-name').value == "" || document.getElementById('custom-field-description').value == "")){
							alert("<?php 
        _e('Please fill in the name and the label of the field', $mf_domain);
        ?>
");
							return false;
						}
						return true;

					}
				</script>
				<!-- END :: Javascript for Image/Photo' Css Class -->

				<?php 
        $field_types = RCCWP_CustomField::GetCustomFieldTypes();
        foreach ($field_types as $field) {
            $checked = $field->name == "Textbox" ? 'checked="checked"' : '';
            ?>
					<label><input name="custom-field-type" value="<?php 
            echo $field->id;
            ?>
" type="radio" <?php 
            echo $checked;
            ?>
 onclick='fun("<?php 
            echo $field->name;
            ?>
");' /> <!-- Calling Javascript Function -->
					<?php 
            echo $field->name;
            ?>
</label><br />
				<?php 
        }
        ?>
			</td>
		</tr>
		<!-- START :: For Image/Photo' Css -->
		<tr valign="top">
			<th scope="row"><div id="divLbl" style="display:none"><?php 
        _e('Css Class', $mf_domain);
        ?>
:</div></th>
			<td>
				<div id="divCSS" style="display:none">
				<input name="custom-field-css" id="custom-field-css" size="40" type="text" value="magicfields" />
				</div>
			</td>
		</tr>
		<!-- END :: For Image/Photo' Css -->
		</tbody>
		</table>


	  	<p class="submit" >
  			<a style="color:black" href="<?php 
        echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('cancel-create-custom-field') . "&custom-group-id={$customGroupID}";
        ?>
" class="button"><?php 
        _e('Cancel', $mf_domain);
        ?>
</a>
  			<input type="submit" id="continue-create-custom-field" value='<?php 
        _e("Continue", $mf_domain);
        ?>
'  onclick="submitForm=true;"/>
  		</p>

  		</form>

  		</div>

  		<?php 
    }
Example #16
0
    public function __construct($rid, $existing, $opts = array())
    {
        $opts = array_merge(array('min_len' => 4, 'count' => 20), $opts);
        require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'Inflect.php';
        $dbh = App::get('db');
        $dbh->setQuery('SELECT t.raw_tag, fa.*
			FROM #__focus_areas fa
			INNER JOIN #__tags t ON t.id = fa.tag_id');
        $this->fa_properties = $dbh->loadAssocList('raw_tag');
        $dbh->setQuery('SELECT raw_tag, (label IS NOT NULL AND label != "") AS is_focus_area
			FROM #__tags_object to1
			INNER JOIN #__tags t ON t.id = to1.tagid
			WHERE to1.tbl = \'resources\' AND to1.objectid = ' . $rid);
        if (!$existing) {
            foreach ($dbh->loadAssocList() as $tag) {
                if ($tag['is_focus_area']) {
                    $this->focus_areas[] = $tag['raw_tag'];
                    $this->existing_fa_map[strtolower($tag['raw_tag'])] = true;
                } else {
                    $this->existing_tags[] = $tag['raw_tag'];
                    $this->existing_map[strtolower($tag['raw_tag'])] = true;
                }
            }
        } else {
            foreach ($existing as $tag) {
                if (!is_null($tag[2])) {
                    $this->existing_fa_map[strtolower($tag[0])] = true;
                } else {
                    $this->existing_tags[] = $tag[0];
                    $this->existing_map[strtolower($tag[0])] = true;
                }
            }
        }
        $dbh->setQuery('SELECT lower(raw_tag) AS raw_tag, CASE WHEN to1.id IS NULL THEN 0 ELSE 1 END AS is_endorsed
			FROM #__tags t
			LEFT JOIN #__tags_object to1 ON to1.tbl = \'tags\' AND to1.objectid = t.id AND to1.label = \'label\' AND to1.tagid = (SELECT id FROM #__tags WHERE tag = \'endorsed\')');
        $tags = array();
        foreach ($dbh->loadAssocList() as $row) {
            $tags[Inflect::singularize($row['raw_tag'])] = $row['is_endorsed'] ? self::ENDORSED_TAG : self::REGULAR_TAG;
            $tags[Inflect::pluralize($row['raw_tag'])] = $row['is_endorsed'] ? self::ENDORSED_TAG : self::REGULAR_TAG;
        }
        $dbh->setQuery('SELECT body FROM #__resource_assoc ra
			LEFT JOIN #__document_resource_rel drr ON drr.resource_id = ra.child_id
			INNER JOIN #__document_text_data dtd ON dtd.id = drr.document_id
			WHERE ra.parent_id = ' . $rid);
        $words = preg_split('/\\W+/', join(' ', $dbh->loadColumn()));
        $word_count = count($words);
        if (!$words[$word_count - 1]) {
            array_pop($words);
            --$word_count;
        }
        $freq = array();
        $last = array();
        foreach ($words as $idx => $word) {
            if (self::is_stop_word($word, $opts['min_len'])) {
                continue;
            }
            $stems = array(array(stem($word), strtolower($word)));
            if (isset($words[$idx + 1]) && !self::is_stop_word($words[$idx + 1], $opts['min_len'])) {
                $stems[] = array($stems[0][0] . ' ' . stem($words[$idx + 1]), strtolower($word) . ' ' . strtolower($words[$idx + 1]));
            }
            if (isset($words[$idx + 2]) && !self::is_stop_word($words[$idx + 2], $opts['min_len'])) {
                $stems[] = array($stems[0][0] . ' ' . stem($words[$idx + 1]) . ' ' . stem($words[$idx + 2]), Inflect::singularize(strtolower($word)) . ' ' . strtolower($words[$idx + 1]) . ' ' . strtolower($words[$idx + 2]));
            }
            foreach ($stems as $set_idx => $set) {
                list($stem, $word) = $set;
                if (isset($this->existing_map[strtolower($word)]) || isset($this->focus_area_map[strtolower($word)])) {
                    continue;
                }
                if (!isset($freq[$stem])) {
                    $freq[$stem] = array('text' => $word, 'count' => 0);
                } else {
                    $freq[$stem]['count'] += ($idx - $last[$stem]) / $word_count * ($set_idx + 1);
                }
                $last[$stem] = $idx;
            }
        }
        foreach ($freq as $stem => $def) {
            foreach (array($stem, $def['text']) as $text) {
                if (isset($tags[$text])) {
                    $freq[$stem]['count'] += $tags[$text] === self::ENDORSED_TAG ? 3 : 1.5;
                    break;
                }
            }
        }
        usort($freq, create_function('$a, $b', 'return $a[\'count\'] === $b[\'count\'] ? 0 : ($a[\'count\'] > $b[\'count\'] ? -1 : 1);'));
        $this->tags = array_slice($freq, 0, $opts['count']);
    }
Example #17
0
 /**
  * Transforma uma palavra para singular
  *
  * @param string $name
  * @return string
  */
 public function singular($name)
 {
     return Inflect::singularize($name);
 }
Example #18
0
 /** Custom SQL Query **/
 function custom($query)
 {
     $this->_result = mysql_query($query, $this->_dbHandle);
     $result = array();
     $table = array();
     $field = array();
     $tempResults = array();
     if (substr_count(strtoupper($query), "SELECT") > 0) {
         if (mysql_num_rows($this->_result) > 0) {
             $numOfFields = mysql_num_fields($this->_result);
             for ($i = 0; $i < $numOfFields; ++$i) {
                 array_push($table, mysql_field_table($this->_result, $i));
                 array_push($field, mysql_field_name($this->_result, $i));
             }
             while ($row = mysql_fetch_row($this->_result)) {
                 for ($i = 0; $i < $numOfFields; ++$i) {
                     $table[$i] = ucfirst(Inflect::singularize($table[$i]));
                     $tempResults[$table[$i]][$field[$i]] = $row[$i];
                 }
                 array_push($result, $tempResults);
             }
         }
         mysql_free_result($this->_result);
     }
     $this->clear();
     return $result;
 }
Example #19
0
 /**
  * Estabilishy a connection with many related records
  *
  * @return void
  * @author wilker
  */
 protected function has_many($expression, $options = array())
 {
     list($model, $name) = $this->parse_relation_expression($expression);
     $this->_relations[$name] = new ActiveRelationMany($this, Inflect::singularize($model), $options);
 }
function pricing_display_calc($data)
{
    return ($data['display_retail_price'] && $data['display_unit_retail_price'] ? '<span class="retail">' . ($_GET['type'] == 'producer_list' ? 'Retail: ' : '') . '$' . number_format($data['display_unit_retail_price'], 2) . '/' . Inflect::singularize($data['pricing_unit']) . '</span><br>' : '') . ($data['display_wholesale_price'] && $data['display_unit_wholesale_price'] ? '<span class="whsle">' . ($_GET['type'] == 'producer_list' ? 'Whsle: ' : '') . '$' . number_format($data['display_unit_wholesale_price'], 2) . '/' . Inflect::singularize($data['pricing_unit']) . '</span><br>' : '') . (($data['display_wholesale_price'] && $data['display_unit_wholesale_price'] || $data['display_retail_price'] && $data['display_unit_retail_price']) && $data['extra_charge'] != 0 ? 'plus<br>' : '') . ($data['extra_charge'] != 0 ? '<span class="extra">' . ($data['extra_charge'] > 0 ? '+' : '-') . '&nbsp;$&nbsp;' . number_format(abs($data['extra_charge']), 2) . '/' . Inflect::singularize($data['ordering_unit']) . '</span><br>' : '');
}
<?php

require_once 'inflect.class.php';
$file_to_prepare = $argv[1];
$data = simplexml_load_file($file_to_prepare);
foreach ($data->object as $obj) {
    echo $singularized_name = Inflect::singularize((string) $obj->attributes()->name);
    $tokens = create_tokens($singularized_name);
    // notseparated lowercase
    $obj->addAttribute('name_ns_lc', build_name($tokens, 'ns_lc'));
    // underline_separated lowercase
    $obj->addAttribute('name_us_lc', build_name($tokens, 'us_lc'));
    // UNDERLINE_SEPARATED uppercase
    $obj->addAttribute('name_us_uc', build_name($tokens, 'us_uc'));
    // camelCase lower-first
    $obj->addAttribute('name_cc_lf', build_name($tokens, 'cc_lf'));
    // CamelCase upper-first
    $obj->addAttribute('name_cc_uf', build_name($tokens, 'cc_uf'));
    foreach ($obj as $field) {
        $tokens = create_tokens((string) $field->attributes()->name);
        $field->addAttribute('name_us_lc', build_name($tokens, 'us_lc'));
        $field->addAttribute('name_cc_lf', build_name($tokens, 'cc_lf'));
    }
}
file_put_contents($file_to_prepare, $data->asXML());
function create_tokens($str)
{
    $tokens = array();
    $token = "";
    for ($i = strlen($str) - 1; $i >= 0; $i--) {
        $char = $str[$i];