Ejemplo n.º 1
0
function get_item_kits_barcode_data($item_kits_ids)
{
    $CI =& get_instance();
    $result = array();
    $item_kit_ids = explode('~', $item_kits_ids);
    foreach ($item_kit_ids as $item_kit_id) {
        $item_kit_info = $CI->Item_kit->get_info($item_kit_id);
        $item_kit_location_info = $CI->Item_kit_location->get_info($item_kit_id);
        $item_kit_price = $item_kit_location_info->unit_price ? $item_kit_location_info->unit_price : $item_kit_info->unit_price;
        if ($CI->config->item('barcode_price_include_tax')) {
            if ($item_kit_info->tax_included) {
                $result[] = array('name' => to_currency($item_kit_price) . ' ' . $item_kit_info->name, 'id' => 'KIT ' . number_pad($item_kit_id, 10));
            } else {
                $result[] = array('name' => to_currency(get_price_for_item_kit_including_taxes($item_kit_id, $item_kit_price)) . ': ' . $item_kit_info->name, 'id' => 'KIT ' . number_pad($item_kit_id, 10));
            }
        } else {
            if ($item_kit_info->tax_included) {
                $result[] = array('name' => to_currency(get_price_for_item_kit_excluding_taxes($item_kit_id, $item_kit_price)) . ': ' . $item_kit_info->name, 'id' => 'KIT ' . number_pad($item_kit_id, 10));
            } else {
                $result[] = array('name' => to_currency($item_kit_price) . ': ' . $item_kit_info->name, 'id' => 'KIT ' . number_pad($item_kit_id, 10));
            }
        }
    }
    return $result;
}
Ejemplo n.º 2
0
function get_items_barcode_data($item_ids)
{
    $CI =& get_instance();
    $result = array();
    $item_ids = explode('~', $item_ids);
    foreach ($item_ids as $item_id) {
        $item_info = $CI->Item->get_info($item_id);
        $item_location_info = $CI->Item_location->get_info($item_id);
        $today = strtotime(date('Y-m-d'));
        $is_item_location_promo = $item_location_info->start_date !== NULL && $item_location_info->end_date !== NULL && (strtotime($item_location_info->start_date) <= $today && strtotime($item_location_info->end_date) >= $today);
        $is_item_promo = $item_info->start_date !== NULL && $item_info->end_date !== NULL && (strtotime($item_info->start_date) <= $today && strtotime($item_info->end_date) >= $today);
        $regular_item_price = $item_location_info->unit_price ? $item_location_info->unit_price : $item_info->unit_price;
        if ($is_item_location_promo) {
            $item_price = $item_location_info->promo_price;
        } elseif ($is_item_promo) {
            $item_price = $item_info->promo_price;
        } else {
            $item_price = $item_location_info->unit_price ? $item_location_info->unit_price : $item_info->unit_price;
        }
        if ($CI->config->item('barcode_price_include_tax')) {
            if ($item_info->tax_included) {
                $result[] = array('name' => ($is_item_location_promo || $is_item_promo ? '<span style="text-decoration: line-through;">' . to_currency($regular_item_price) . '</span> ' : ' ') . to_currency($item_price) . ': ' . $item_info->name, 'id' => number_pad($item_id, 10));
            } else {
                $result[] = array('name' => ($is_item_location_promo || $is_item_promo ? '<span style="text-decoration: line-through;">' . to_currency(get_price_for_item_including_taxes($item_id, $regular_item_price)) . '</span> ' : ' ') . to_currency(get_price_for_item_including_taxes($item_id, $item_price)) . ': ' . $item_info->name, 'id' => number_pad($item_id, 10));
            }
        } else {
            if ($item_info->tax_included) {
                $result[] = array('name' => ($is_item_location_promo || $is_item_promo ? '<span style="text-decoration: line-through;">' . to_currency(get_price_for_item_excluding_taxes($item_id, $regular_item_price)) . '</span> ' : ' ') . to_currency(get_price_for_item_excluding_taxes($item_id, $item_price)) . ': ' . $item_info->name, 'id' => number_pad($item_id, 10));
            } else {
                $result[] = array('name' => ($is_item_location_promo || $is_item_promo ? '<span style="text-decoration: line-through;">' . to_currency($regular_item_price) . '</span> ' : ' ') . to_currency($item_price) . ': ' . $item_info->name, 'id' => number_pad($item_id, 10));
            }
        }
    }
    return $result;
}
function process_medal($row)
{
    $materials = array_filter(explode('|', $row['material']));
    $manufactures = array_filter(explode('|', $row['manufacture']));
    $manufacture_array = array();
    $material_array = array();
    if (count($manufactures) > 0) {
        foreach ($manufactures as $manufacture) {
            $manufacture_array[] = normalize_manufacture(trim($manufacture));
        }
    }
    if (count($materials) > 0) {
        foreach ($materials as $material) {
            $material_array[] = normalize_material(trim($material));
        }
    }
    if (is_numeric(trim($row['measurements']))) {
        $diameter = trim($row['measurements']);
    } else {
        $diameter = '';
    }
    return array('material' => implode('|', $material_array), 'manufacture' => implode('|', $manufacture_array), 'diameter' => number_pad($diameter, 4));
}
Ejemplo n.º 4
0
 function render()
 {
     //debug
     $debug = $_REQUEST['debug'];
     // array
     //get the variables
     $domain_uuid = $this->domain_uuid;
     $device_template = $this->device_template;
     $template_dir = $this->template_dir;
     $mac = $this->mac;
     $file = $this->file;
     //get the device template
     if (strlen($_REQUEST['template']) > 0) {
         $device_template = $_REQUEST['template'];
         $search = array('..', '/./');
         $device_template = str_replace($search, "", $device_template);
         $device_template = str_replace('//', '/', $device_template);
     }
     //remove ../ and slashes in the file name
     $search = array('..', '/', '\\', '/./', '//');
     $file = str_replace($search, "", $file);
     //get the domain_name
     if (strlen($domain_name) == 0) {
         $sql = "SELECT domain_name FROM v_domains ";
         $sql .= "WHERE domain_uuid=:domain_uuid ";
         $prep_statement = $this->db->prepare(check_sql($sql));
         if ($prep_statement) {
             //use the prepared statement
             $prep_statement->bindParam(':domain_uuid', $domain_uuid);
             $prep_statement->execute();
             $row = $prep_statement->fetch();
             unset($prep_statement);
             //set the variables from values in the database
             $domain_name = $row["domain_name"];
         }
     }
     //build the provision array
     foreach ($_SESSION['provision'] as $key => $val) {
         if (strlen($val['var']) > 0) {
             $value = $val['var'];
         }
         if (strlen($val['text']) > 0) {
             $value = $val['text'];
         }
         $provision[$key] = $value;
     }
     //check to see if the mac_address exists in devices
     if (strlen($_REQUEST['user_id']) == 0 || strlen($_REQUEST['userid']) == 0) {
         if ($this->mac_exists($mac)) {
             //get the device_template
             if (strlen($device_template) == 0) {
                 $sql = "SELECT * FROM v_devices ";
                 $sql .= "WHERE device_mac_address=:mac ";
                 //$sql .= "WHERE device_mac_address= '$mac' ";
                 $prep_statement_2 = $this->db->prepare(check_sql($sql));
                 if ($prep_statement_2) {
                     //use the prepared statement
                     $prep_statement_2->bindParam(':mac', $mac);
                     $prep_statement_2->execute();
                     $row = $prep_statement_2->fetch();
                     //set the variables from values in the database
                     $device_uuid = $row["device_uuid"];
                     $device_label = $row["device_label"];
                     if (strlen($row["device_vendor"]) > 0) {
                         $device_vendor = strtolower($row["device_vendor"]);
                     }
                     $device_model = $row["device_model"];
                     $device_firmware_version = $row["device_firmware_version"];
                     $device_provision_enable = $row["device_provision_enable"];
                     $device_template = $row["device_template"];
                     $device_profile_uuid = $row["device_profile_uuid"];
                     $device_description = $row["device_description"];
                 }
             }
             //find a template that was defined on another phone and use that as the default.
             if (strlen($device_template) == 0) {
                 $sql = "SELECT * FROM v_devices ";
                 $sql .= "WHERE domain_uuid=:domain_uuid ";
                 $sql .= "limit 1 ";
                 $prep_statement_3 = $this->db->prepare(check_sql($sql));
                 if ($prep_statement_3) {
                     $prep_statement_3->bindParam(':domain_uuid', $domain_uuid);
                     $prep_statement_3->execute();
                     $row = $prep_statement_3->fetch();
                     $device_label = $row["device_label"];
                     $device_vendor = strtolower($row["device_vendor"]);
                     $device_model = $row["device_model"];
                     $device_firmware_version = $row["device_firmware_version"];
                     $device_provision_enable = $row["device_provision_enable"];
                     $device_template = $row["device_template"];
                     $device_profile_uuid = $row["device_profile_uuid"];
                     $device_description = $row["device_description"];
                 }
             }
         } else {
             //use the user_agent to pre-assign a template for 1-hit provisioning. Enter the a unique string to match in the user agent, and the template it should match.
             $template_list = array("Linksys/SPA-2102" => "linksys/spa2102", "Linksys/SPA-3102" => "linksys/spa3102", "Linksys/SPA-9212" => "linksys/spa921", "Cisco/SPA301" => "cisco/spa301", "Cisco/SPA301D" => "cisco/spa302d", "Cisco/SPA303" => "cisco/spa303", "Cisco/SPA501G" => "cisco/spa501g", "Cisco/SPA502G" => "cisco/spa502g", "Cisco/SPA504G" => "cisco/spa504g", "Cisco/SPA508G" => "cisco/spa508g", "Cisco/SPA509G" => "cisco/spa509g", "Cisco/SPA512G" => "cisco/spa512g", "Cisco/SPA514G" => "cisco/spa514g", "Cisco/SPA525G2" => "cisco/spa525g2", "snom300-SIP" => "snom/300", "snom320-SIP" => "snom/320", "snom360-SIP" => "snom/360", "snom370-SIP" => "snom/370", "snom820-SIP" => "snom/820", "snom-m3-SIP" => "snom/m3", "yealink SIP-T20" => "yealink/t20", "yealink SIP-T22" => "yealink/t22", "yealink SIP-T26" => "yealink/t26", "Yealink SIP-T32" => "yealink/t32", "HW GXP1450" => "grandstream/gxp1450", "HW GXP2124" => "grandstream/gxp2124", "HW GXV3140" => "grandstream/gxv3140", "HW GXV3175" => "grandstream/gxv3175", "Wget/1.11.3" => "konftel/kt300ip");
             foreach ($template_list as $key => $val) {
                 if (stripos($_SERVER['HTTP_USER_AGENT'], $key) !== false) {
                     $device_template = $val;
                     break;
                 }
             }
             unset($template_list);
             //mac address does not exist in the table so add it
             if ($_SESSION['provision']['auto_insert_enabled']['boolean'] == "true" and strlen($domain_uuid) > 0) {
                 $device_uuid = uuid();
                 $sql = "INSERT INTO v_devices ";
                 $sql .= "(";
                 $sql .= "domain_uuid, ";
                 $sql .= "device_uuid, ";
                 $sql .= "device_mac_address, ";
                 $sql .= "device_vendor, ";
                 $sql .= "device_model, ";
                 $sql .= "device_provision_enable, ";
                 $sql .= "device_template, ";
                 $sql .= "device_description ";
                 $sql .= ") ";
                 $sql .= "VALUES ";
                 $sql .= "(";
                 $sql .= "'" . $domain_uuid . "', ";
                 $sql .= "'{$device_uuid}', ";
                 $sql .= "'{$mac}', ";
                 $sql .= "'{$device_vendor}', ";
                 $sql .= "'', ";
                 $sql .= "'true', ";
                 $sql .= "'{$device_template}', ";
                 $sql .= "'auto {$_SERVER['HTTP_USER_AGENT']}' ";
                 $sql .= ")";
                 $this->db->exec(check_sql($sql));
                 unset($sql);
             }
         }
     }
     //alternate device_uuid
     if (strlen($device_uuid) > 0) {
         $sql = "SELECT * FROM v_devices ";
         $sql .= "WHERE device_uuid = '" . $device_uuid . "' ";
         $prep_statement_3 = $this->db->prepare(check_sql($sql));
         if ($prep_statement_3) {
             $prep_statement_3->execute();
             $row = $prep_statement_3->fetch();
             $device_uuid_alternate = $row["device_uuid_alternate"];
             if (is_uuid($device_uuid_alternate)) {
                 //override the original device_uuid
                 $device_uuid = $device_uuid_alternate;
                 //get the new devices information
                 $sql = "SELECT * FROM v_devices ";
                 $sql .= "WHERE device_uuid = '" . $device_uuid . "' ";
                 $prep_statement_4 = $this->db->prepare(check_sql($sql));
                 if ($prep_statement_4) {
                     $prep_statement_4->execute();
                     $row = $prep_statement_4->fetch();
                     $device_label = $row["device_label"];
                     $device_vendor = strtolower($row["device_vendor"]);
                     $device_firmware_version = $row["device_firmware_version"];
                     $device_provision_enable = $row["device_provision_enable"];
                     //keep the original template
                     $device_profile_uuid = $row["device_profile_uuid"];
                     $device_description = $row["device_description"];
                 }
                 unset($prep_statement_4);
             }
         }
         unset($prep_statement_3);
     }
     //get the device settings table in the provision category and update the provision array
     if (strlen($device_uuid) > 0) {
         $sql = "SELECT * FROM v_device_settings ";
         $sql .= "WHERE device_uuid = '" . $device_uuid . "' ";
         $sql .= "AND device_setting_enabled = 'true' ";
         $prep_statement = $this->db->prepare(check_sql($sql));
         $prep_statement->execute();
         $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
         $result_count = count($result);
         foreach ($result as $row) {
             $key = $row['device_setting_subcategory'];
             $value = $row['device_setting_value'];
             $provision[$key] = $value;
         }
         unset($prep_statement);
     }
     //initialize a template object
     $view = new template();
     if (strlen($_SESSION['provision']['template_engine']['text']) > 0) {
         $view->engine = $_SESSION['provision']['template_engine']['text'];
         //raintpl, smarty, twig
     } else {
         $view->engine = "smarty";
     }
     $view->template_dir = $template_dir . "/" . $device_template . "/";
     $view->cache_dir = $_SESSION['server']['temp']['dir'];
     $view->init();
     //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number
     //get the time zone
     $time_zone_name = $_SESSION['domain']['time_zone']['name'];
     if (strlen($time_zone_name) > 0) {
         $time_zone_offset_raw = get_time_zone_offset($time_zone_name) / 3600;
         $time_zone_offset_hours = floor($time_zone_offset_raw);
         $time_zone_offset_minutes = ($time_zone_offset_raw - $time_zone_offset_hours) * 60;
         $time_zone_offset_minutes = number_pad($time_zone_offset_minutes, 2);
         if ($time_zone_offset_raw > 0) {
             $time_zone_offset_hours = number_pad($time_zone_offset_hours, 2);
             $time_zone_offset_hours = "+" . $time_zone_offset_hours;
         } else {
             $time_zone_offset_hours = str_replace("-", "", $time_zone_offset_hours);
             $time_zone_offset_hours = "-" . number_pad($time_zone_offset_hours, 2);
         }
         $time_zone_offset = $time_zone_offset_hours . ":" . $time_zone_offset_minutes;
         $view->assign("time_zone_offset", $time_zone_offset);
     }
     //create a mac address with back slashes for backwards compatability
     $mac_dash = substr($mac, 0, 2) . '-' . substr($mac, 2, 2) . '-' . substr($mac, 4, 2) . '-' . substr($mac, 6, 2) . '-' . substr($mac, 8, 2) . '-' . substr($mac, 10, 2);
     //get the contacts array and add to the template engine
     if (strlen($device_uuid) > 0 and strlen($domain_uuid) > 0 and $_SESSION['provision']['directory']['boolean'] == "true") {
         //get contacts from the database
         $sql = "select c.contact_organization, c.contact_name_given, c.contact_name_family, p.phone_number, p.phone_extension ";
         $sql .= "from v_contacts as c, v_contact_phones as p ";
         $sql .= "where c.domain_uuid = '" . $domain_uuid . "' ";
         $sql .= "and c.contact_uuid = p.contact_uuid ";
         $sql .= "and p.phone_type_voice = '1' ";
         $sql .= "order by c.contact_organization desc, c.contact_name_given asc, c.contact_name_family asc ";
         $prep_statement = $this->db->prepare(check_sql($sql));
         $prep_statement->execute();
         $contacts = $prep_statement->fetchAll(PDO::FETCH_NAMED);
         unset($prep_statement, $sql);
         //assign the contacts array
         $view->assign("contacts", $contacts);
     }
     //get the provisioning information from device lines table
     if (strlen($device_uuid) > 0) {
         //get the device lines array
         $sql = "select * from v_device_lines ";
         $sql .= "where device_uuid = '" . $device_uuid . "' ";
         $sql .= "and (enabled = 'true' or enabled is null or enabled = '') ";
         $prep_statement = $this->db->prepare(check_sql($sql));
         $prep_statement->execute();
         $device_lines = $prep_statement->fetchAll(PDO::FETCH_NAMED);
         //assign the keys array
         $view->assign("lines", $device_lines);
         //set the variables
         foreach ($device_lines as $row) {
             //set the variables
             $line_number = $row['line_number'];
             $register_expires = $row['register_expires'];
             $sip_transport = strtolower($row['sip_transport']);
             $sip_port = $row['sip_port'];
             //set defaults
             if (strlen($register_expires) == 0) {
                 $register_expires = "120";
             }
             if (strlen($sip_transport) == 0) {
                 $sip_transport = "tcp";
             }
             if (strlen($sip_port) == 0) {
                 if ($line_number == "" || $line_number == "1") {
                     $sip_port = "5060";
                 } else {
                     $sip_port = "506" . ($line_number + 1);
                 }
             }
             //set a lines array index is the line number
             $lines[$line_number]['register_expires'] = $register_expires;
             $lines[$line_number]['sip_transport'] = strtolower($sip_transport);
             $lines[$line_number]['sip_port'] = $sip_port;
             $lines[$line_number]['server_address'] = $row["server_address"];
             $lines[$line_number]['outbound_proxy'] = $row["outbound_proxy"];
             $lines[$line_number]['display_name'] = $row["display_name"];
             $lines[$line_number]['auth_id'] = $row["auth_id"];
             $lines[$line_number]['user_id'] = $row["user_id"];
             $lines[$line_number]['password'] = $row["password"];
             //assign the variables
             $view->assign("server_address_" . $line_number, $row["server_address"]);
             $view->assign("outbound_proxy_" . $line_number, $row["outbound_proxy"]);
             $view->assign("display_name_" . $line_number, $row["display_name"]);
             $view->assign("auth_id_" . $line_number, $row["auth_id"]);
             $view->assign("user_id_" . $line_number, $row["user_id"]);
             $view->assign("user_password_" . $line_number, $row["password"]);
             $view->assign("sip_transport_" . $line_number, $sip_transport);
             $view->assign("sip_port_" . $line_number, $sip_port);
             $view->assign("register_expires_" . $line_number, $register_expires);
         }
         unset($prep_statement);
     }
     //get the provisioning information from device keys
     if (strlen($device_uuid) > 0) {
         //get the device keys array
         $sql = "SELECT * FROM v_device_keys ";
         $sql .= "WHERE (";
         $sql .= "device_uuid = '" . $device_uuid . "' ";
         if (strlen($device_profile_uuid) > 0) {
             $sql .= "or device_profile_uuid = '" . $device_profile_uuid . "' ";
         }
         $sql .= ") ";
         //$sql .= "AND domain_uuid = '".$domain_uuid."' ";
         $sql .= "ORDER BY device_key_category asc, device_key_id asc, device_uuid desc";
         $prep_statement = $this->db->prepare(check_sql($sql));
         $prep_statement->execute();
         $device_keys = $prep_statement->fetchAll(PDO::FETCH_NAMED);
         //rebuild the array to allow profile keys to be overridden by keys assigned to this device
         $x = 0;
         $previous_category = '';
         $previous_id = '';
         foreach ($device_keys as $row) {
             //set the variables
             if ($row['device_key_category'] == $previous_category && $row['device_key_id'] == $previous_id) {
                 $device_keys[$x]['device_key_override'] = "true";
                 $device_keys[$x]['device_key_message'] = "value=" . $device_keys[$x - 1]['device_key_value'] . "&label=" . $device_keys[$x - 1]['device_key_label'];
                 unset($device_keys[$x - 1]);
             }
             $device_keys[$x]['device_key_category'] = $row['device_key_category'];
             $device_keys[$x]['device_key_id'] = $row['device_key_id'];
             //1
             $device_keys[$x]['device_key_type'] = $row['device_key_type'];
             //line, memory, expansion
             $device_keys[$x]['device_key_line'] = $row['device_key_line'];
             $device_keys[$x]['device_key_value'] = $row['device_key_value'];
             //1
             $device_keys[$x]['device_key_extension'] = $row['device_key_extension'];
             $device_keys[$x]['device_key_label'] = $row['device_key_label'];
             //label
             if (is_uuid($row['device_profile_uuid'])) {
                 $device_keys[$x]['device_key_owner'] = "profile";
             } else {
                 $device_keys[$x]['device_key_owner'] = "device";
             }
             //set previous values
             $previous_category = $row['device_key_category'];
             $previous_id = $row['device_key_id'];
             //increment the key
             $x++;
         }
     }
     //debug information
     if ($debug == "array") {
         echo "<pre>\n";
         print_r($device_keys);
         echo "<pre>\n";
         exit;
     }
     //assign the keys array
     $view->assign("keys", $device_keys);
     //set the variables
     foreach ($device_keys as $row) {
         //set the variables
         $device_key_category = $row['device_key_category'];
         $device_key_id = $row['device_key_id'];
         //1
         $device_key_type = $row['device_key_type'];
         //line
         $device_key_line = $row['device_key_line'];
         $device_key_value = $row['device_key_value'];
         //1
         $device_key_extension = $row['device_key_extension'];
         $device_key_label = $row['device_key_label'];
         //label
         //set the line key
         $x = $device_key_line;
         //add a simple variable with the index
         if ($x === 0 || $x === 1) {
             $device_key_value = str_replace("\${user_id}", $lines[$x]['user_id'], $device_key_value);
             $device_key_value = str_replace("\${auth_id}", $lines[$x]['auth_id'], $device_key_value);
             $device_key_value = str_replace("\${extension}", $lines[$x]['user_id'], $device_key_value);
             $device_key_value = str_replace("\${password}", $lines[$x]['password'], $device_key_value);
             $device_key_value = str_replace("\${register_expires}", $lines[$x]['register_expires'], $device_key_value);
             $device_key_value = str_replace("\${sip_transport}", $lines[$x]['sip_transport'], $device_key_value);
             $device_key_value = str_replace("\${sip_port}", $lines[$x]['sip_port'], $device_key_value);
             $device_key_value = str_replace("\${server_address}", $lines[$x]['server_address'], $device_key_value);
             $device_key_value = str_replace("\${outbound_proxy}", $lines[$x]['outbound_proxy'], $device_key_value);
             $device_key_value = str_replace("\${display_name}", $lines[$x]['display_name'], $device_key_value);
             $device_key_extension = str_replace("\${user_id}", $lines[$x]['user_id'], $device_key_extension);
             $device_key_extension = str_replace("\${auth_id}", $lines[$x]['auth_id'], $device_key_extension);
             $device_key_extension = str_replace("\${extension}", $lines[$x]['user_id'], $device_key_extension);
             $device_key_extension = str_replace("\${password}", $lines[$x]['password'], $device_key_extension);
             $device_key_extension = str_replace("\${register_expires}", $lines[$x]['register_expires'], $device_key_extension);
             $device_key_extension = str_replace("\${sip_transport}", $lines[$x]['sip_transport'], $device_key_extension);
             $device_key_extension = str_replace("\${sip_port}", $lines[$x]['sip_port'], $device_key_extension);
             $device_key_extension = str_replace("\${server_address}", $lines[$x]['server_address'], $device_key_extension);
             $device_key_extension = str_replace("\${outbound_proxy}", $lines[$x]['outbound_proxy'], $device_key_extension);
             $device_key_extension = str_replace("\${display_name}", $lines[$x]['display_name'], $device_key_extension);
             $device_key_label = str_replace("\${user_id}", $lines[$x]['user_id'], $device_key_label);
             $device_key_label = str_replace("\${auth_id}", $lines[$x]['auth_id'], $device_key_label);
             $device_key_label = str_replace("\${extension}", $lines[$x]['user_id'], $device_key_label);
             $device_key_label = str_replace("\${password}", $lines[$x]['password'], $device_key_label);
             $device_key_label = str_replace("\${register_expires}", $lines[$x]['register_expires'], $device_key_label);
             $device_key_label = str_replace("\${sip_transport}", $lines[$x]['sip_transport'], $device_key_label);
             $device_key_label = str_replace("\${sip_port}", $lines[$x]['sip_port'], $device_key_label);
             $device_key_label = str_replace("\${server_address}", $lines[$x]['server_address'], $device_key_label);
             $device_key_label = str_replace("\${outbound_proxy}", $lines[$x]['outbound_proxy'], $device_key_label);
             $device_key_label = str_replace("\${display_name}", $lines[$x]['display_name'], $device_key_label);
         }
         //add variables with the index
         $device_key_value = str_replace("\${user_id_{$x}}", $lines[$x]['user_id'], $device_key_value);
         $device_key_value = str_replace("\${auth_id_{$x}}", $lines[$x]['auth_id'], $device_key_value);
         $device_key_value = str_replace("\${extension_{$x}}", $lines[$x]['user_id'], $device_key_value);
         $device_key_value = str_replace("\${password_{$x}}", $lines[$x]['password'], $device_key_value);
         $device_key_value = str_replace("\${register_expires_{$x}}", $lines[$x]['register_expires'], $device_key_value);
         $device_key_value = str_replace("\${sip_transport_{$x}}", $lines[$x]['sip_transport'], $device_key_value);
         $device_key_value = str_replace("\${sip_port_{$x}}", $lines[$x]['sip_port'], $device_key_value);
         $device_key_value = str_replace("\${server_address_{$x}}", $lines[$x]['server_address'], $device_key_value);
         $device_key_value = str_replace("\${outbound_proxy_{$x}}", $lines[$x]['outbound_proxy'], $device_key_value);
         $device_key_value = str_replace("\${display_name_{$x}}", $lines[$x]['display_name'], $device_key_value);
         $device_key_extension = str_replace("\${user_id_{$x}}", $lines[$x]['user_id'], $device_key_label);
         $device_key_extension = str_replace("\${auth_id_{$x}}", $lines[$x]['auth_id'], $device_key_label);
         $device_key_extension = str_replace("\${extension_{$x}}", $lines[$x]['user_id'], $device_key_label);
         $device_key_extension = str_replace("\${password_{$x}}", $lines[$x]['password'], $device_key_label);
         $device_key_extension = str_replace("\${register_expires_{$x}}", $lines[$x]['register_expires'], $device_key_label);
         $device_key_extension = str_replace("\${sip_transport_{$x}}", $lines[$x]['sip_transport'], $device_key_label);
         $device_key_extension = str_replace("\${sip_port_{$x}}", $lines[$x]['sip_port'], $device_key_label);
         $device_key_extension = str_replace("\${server_address_{$x}}", $lines[$x]['server_address'], $device_key_label);
         $device_key_extension = str_replace("\${outbound_proxy_{$x}}", $lines[$x]['outbound_proxy'], $device_key_label);
         $device_key_extension = str_replace("\${display_name_{$x}}", $lines[$x]['display_name'], $device_key_label);
         $device_key_label = str_replace("\${user_id_{$x}}", $lines[$x]['user_id'], $device_key_label);
         $device_key_label = str_replace("\${auth_id_{$x}}", $lines[$x]['auth_id'], $device_key_label);
         $device_key_label = str_replace("\${extension_{$x}}", $lines[$x]['user_id'], $device_key_label);
         $device_key_label = str_replace("\${password_{$x}}", $lines[$x]['password'], $device_key_label);
         $device_key_label = str_replace("\${register_expires_{$x}}", $lines[$x]['register_expires'], $device_key_label);
         $device_key_label = str_replace("\${sip_transport_{$x}}", $lines[$x]['sip_transport'], $device_key_label);
         $device_key_label = str_replace("\${sip_port_{$x}}", $lines[$x]['sip_port'], $device_key_label);
         $device_key_label = str_replace("\${server_address_{$x}}", $lines[$x]['server_address'], $device_key_label);
         $device_key_label = str_replace("\${outbound_proxy_{$x}}", $lines[$x]['outbound_proxy'], $device_key_label);
         $device_key_label = str_replace("\${display_name_{$x}}", $lines[$x]['display_name'], $device_key_label);
         //add general variables
         $device_key_value = str_replace("\${domain_name}", $domain_name, $device_key_value);
         $device_key_extension = str_replace("\${domain_name}", $domain_name, $device_key_extension);
         $device_key_label = str_replace("\${domain_name}", $domain_name, $device_key_label);
         //grandstream modes are different based on the category
         if ($device_vendor == "grandstream") {
             if ($device_key_category == "line") {
                 switch ($device_key_type) {
                     case "line":
                         $device_key_type = "0";
                         break;
                     case "shared line":
                         $device_key_type = "1";
                         break;
                     case "speed dial":
                         $device_key_type = "10";
                         break;
                     case "blf":
                         $device_key_type = "11";
                         break;
                     case "presence watcher":
                         $device_key_type = "12";
                         break;
                     case "eventlist blf":
                         $device_key_type = "13";
                         break;
                     case "speed dial active":
                         $device_key_type = "14";
                         break;
                     case "dial dtmf":
                         $device_key_type = "15";
                         break;
                     case "voicemail":
                         $device_key_type = "16";
                         break;
                     case "call return":
                         $device_key_type = "17";
                         break;
                     case "transfer":
                         $device_key_type = "18";
                         break;
                     case "call park":
                         $device_key_type = "19";
                         break;
                     case "intercom":
                         $device_key_type = "20";
                         break;
                     case "ldap search":
                         $device_key_type = "21";
                         break;
                 }
             }
             if ($device_key_category == "memory") {
                 switch ($device_key_type) {
                     case "speed dial":
                         $device_key_type = "0";
                         break;
                     case "blf":
                         $device_key_type = "1";
                         break;
                     case "presence watcher":
                         $device_key_type = "2";
                         break;
                     case "eventlist blf":
                         $device_key_type = "3";
                         break;
                     case "speed dial active":
                         $device_key_type = "4";
                         break;
                     case "dial dtmf":
                         $device_key_type = "5";
                         break;
                     case "voicemail":
                         $device_key_type = "6";
                         break;
                     case "call return":
                         $device_key_type = "7";
                         break;
                     case "transfer":
                         $device_key_type = "8";
                         break;
                     case "call park":
                         $device_key_type = "9";
                         break;
                     case "intercom":
                         $device_key_type = "10";
                         break;
                     case "ldap search":
                         $device_key_type = "11";
                         break;
                 }
             }
         }
         //assign the variables
         if (strlen($device_key_category) == 0) {
             $view->assign("key_id_" . $device_key_id, $device_key_id);
             $view->assign("key_type_" . $device_key_id, $device_key_type);
             $view->assign("key_line_" . $device_key_id, $device_key_line);
             $view->assign("key_value_" . $device_key_id, $device_key_value);
             $view->assign("key_extension_" . $device_key_id, $device_key_extension);
             $view->assign("key_label_" . $device_key_id, $device_key_label);
         } else {
             $view->assign($device_key_category . "_key_id_" . $device_key_id, $device_key_id);
             $view->assign($device_key_category . "_key_type_" . $device_key_id, $device_key_type);
             $view->assign($device_key_category . "_key_line_" . $device_key_id, $device_key_line);
             $view->assign($device_key_category . "_key_value_" . $device_key_id, $device_key_value);
             $view->assign($device_key_category . "_key_extension_" . $device_key_id, $device_key_extension);
             $view->assign($device_key_category . "_key_label_" . $device_key_id, $device_key_label);
         }
     }
     unset($prep_statement);
     //set the mac address in the correct format
     switch (strtolower($device_vendor)) {
         case "aastra":
             $mac = strtoupper($mac);
             break;
         case "snom":
             $mac = strtolower($mac);
             break;
         case "polycom":
             $mac = strtolower($mac);
             break;
         default:
             $mac = strtolower($mac);
             $mac = substr($mac, 0, 2) . '-' . substr($mac, 2, 2) . '-' . substr($mac, 4, 2) . '-' . substr($mac, 6, 2) . '-' . substr($mac, 8, 2) . '-' . substr($mac, 10, 2);
     }
     //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number
     $view->assign("mac", $mac);
     $view->assign("label", $device_label);
     $view->assign("firmware_version", $device_firmware_version);
     $view->assign("domain_name", $domain_name);
     $view->assign("project_path", PROJECT_PATH);
     $view->assign("server1_address", $server1_address);
     $view->assign("proxy1_address", $proxy1_address);
     $view->assign("user_id", $user_id);
     $view->assign("password", $password);
     $view->assign("template", $device_template);
     //replace the dynamic provision variables that are defined in default, domain, and device settings
     foreach ($provision as $key => $val) {
         $view->assign($key, $val);
     }
     //set the template directory
     if (strlen($provision["template_dir"]) > 0) {
         $template_dir = $provision["template_dir"];
     }
     //if the domain name directory exists then only use templates from it
     if (is_dir($template_dir . '/' . $domain_name)) {
         $device_template = $domain_name . '/' . $device_template;
     }
     //if $file is not provided then look for a default file that exists
     if (strlen($file) == 0) {
         if (file_exists($template_dir . "/" . $device_template . "/{\$mac}")) {
             $file = "{\$mac}";
         } elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}.xml")) {
             $file = "{\$mac}.xml";
         } elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}.cfg")) {
             $file = "{\$mac}.cfg";
         } else {
             echo "file not found";
             exit;
         }
     } else {
         //make sure the file exists
         if (!file_exists($template_dir . "/" . $device_template . "/" . $file)) {
             echo "file not found";
             if ($_SESSION['provision']['debug']['boolean'] == 'true') {
                 echo ":{$template_dir}/{$device_template}/{$file}<br/>";
                 echo "template_dir: {$template_dir}<br/>";
                 echo "device_template: {$device_template}<br/>";
                 echo "file: {$file}";
             }
             exit;
         }
     }
     //output template to string for header processing
     $file_contents = $view->render($file);
     //log file for testing
     if ($_SESSION['provision']['debug']['boolean'] == 'true') {
         $tmp_file = "/tmp/provisioning_log.txt";
         $fh = fopen($tmp_file, 'w') or die("can't open file");
         $tmp_string = $mac . "\n";
         fwrite($fh, $tmp_string);
         fclose($fh);
     }
     //returned the rendered template
     return $file_contents;
 }
Ejemplo n.º 5
0
 echo "\t<br />";
 echo "</div>";
 if ($action == 'update' && is_array($current_presets) && $current_presets[$preset_number] != '') {
     //add (potentially customized) preset conditions and populate
     foreach ($current_conditions[$preset_group_id] as $cond_var => $cond_val) {
         $range_indicator = $cond_var == 'date-time' ? '~' : '-';
         $tmp = explode($range_indicator, $cond_val);
         $cond_val_start = $tmp[0];
         $cond_val_stop = $tmp[1];
         unset($tmp);
         //convert minute-of-day to time-of-day values
         if ($cond_var == 'minute-of-day') {
             $cond_var = 'time-of-day';
             $cond_val_start = number_pad(floor($cond_val_start / 60), 2) . ":" . number_pad(fmod($cond_val_start, 60), 2);
             if ($cond_val_stop != '') {
                 $cond_val_stop = number_pad(floor($cond_val_stop / 60), 2) . ":" . number_pad(fmod($cond_val_stop, 60), 2);
             }
         }
         echo "<script>\n";
         echo "\tcondition_id = add_condition(" . $preset_group_id . ",'preset');\n";
         echo "\t\$('#variable_" . $preset_group_id . "_' + condition_id + ' option[value=\"" . $cond_var . "\"]').prop('selected', true);\n";
         if ($cond_var == 'date-time') {
             echo "\tchange_to_input(document.getElementById('value_" . $preset_group_id . "_' + condition_id + '_start'));\n";
             echo "\tchange_to_input(document.getElementById('value_" . $preset_group_id . "_' + condition_id + '_stop'));\n";
             echo "\t\$('#value_" . $preset_group_id . "_' + condition_id + '_start').val('" . $cond_val_start . "');\n";
             echo "\t\$('#value_" . $preset_group_id . "_' + condition_id + '_stop').val('" . $cond_val_stop . "');\n";
         } else {
             echo "\tload_value_fields(" . $preset_group_id . ", condition_id, '" . $cond_var . "');\n";
             echo "\t\$('#value_" . $preset_group_id . "_' + condition_id + '_start option[value=\"" . $cond_val_start . "\"]').prop('selected', true);\n";
             echo "\t\$('#value_" . $preset_group_id . "_' + condition_id + '_stop option[value=\"" . $cond_val_stop . "\"]').prop('selected', true);\n";
         }
<div class="error">The following judging number(s) have already been assigned to entries. Please use another judging number for each.<br /><?php 
    echo rtrim($jnum_info, "<br>");
    ?>
</div>
<?php 
}
if (!empty($flag_enum)) {
    // Build list of already used numbers and the entry number that it was associated with at scan
    $enum_info = "";
    foreach ($flag_enum as $num) {
        if ($num != "") {
            $num = explode("*", $num);
            if (NHC && $prefix == "final_") {
                $enum_info .= "<li>Entry " . number_pad($num[1], 6) . " has already been assigned judging number " . $num[0] . "</li>";
            } else {
                $enum_info .= "<li>Entry " . number_pad($num[1], 4) . " has already been assigned judging number " . $num[0] . "</li>";
            }
        }
    }
    ?>
<div class="error">The following entries already have 6 digit judging numbers assigned to them - the original 6 digit judging number has been kept. <ul style="font-size: .9em; font-weight:normal; "><?php 
    echo $enum_info;
    ?>
</ul>If any of the above are incorrect, you can update its judging number via the <a href="<?php 
    $base_url;
    ?>
index.php?section=admin&amp;go=entries">Administration: Entries</a> list.</div>
<?php 
}
?>
<h2>Check-In Entries with a Barcode Reader/Scanner</h2>
Ejemplo n.º 7
0
            if ($x > 0) {
                echo "\t\t</optgroup>\n";
            }
            echo "\t\t<optgroup label='" . $category . "'>\n";
        }
        if (strlen($val) > 0) {
            $time_zone_offset = get_time_zone_offset($val) / 3600;
            $time_zone_offset_hours = floor($time_zone_offset);
            $time_zone_offset_minutes = ($time_zone_offset - $time_zone_offset_hours) * 60;
            $time_zone_offset_minutes = number_pad($time_zone_offset_minutes, 2);
            if ($time_zone_offset > 0) {
                $time_zone_offset_hours = number_pad($time_zone_offset_hours, 2);
                $time_zone_offset_hours = "+" . $time_zone_offset_hours;
            } else {
                $time_zone_offset_hours = str_replace("-", "", $time_zone_offset_hours);
                $time_zone_offset_hours = "-" . number_pad($time_zone_offset_hours, 2);
            }
        }
        if ($val == $default_setting_value) {
            echo "\t\t\t<option value='" . $val . "' selected='selected'>(UTC " . $time_zone_offset_hours . ":" . $time_zone_offset_minutes . ") " . $val . "</option>\n";
        } else {
            echo "\t\t\t<option value='" . $val . "'>(UTC " . $time_zone_offset_hours . ":" . $time_zone_offset_minutes . ") " . $val . "</option>\n";
        }
        $previous_category = $category;
        $x++;
    }
    echo "\t\t</select>\n";
} elseif ($subcategory == 'password' || substr_count($subcategory, '_password') > 0 || $category == "login" && $subcategory == "password_reset_key" && $name == "text") {
    echo "\t<input class='formfld' type='password' name='default_setting_value' onmouseover=\"this.type='text';\" onfocus=\"this.type='text';\" onmouseout=\"if (!\$(this).is(':focus')) { this.type='password'; }\" onblur=\"this.type='password';\" maxlength='255' value=\"" . $default_setting_value . "\">\n";
} elseif ($category == "theme" && $subcategory == "background_color" && $name == "array" || $category == "theme" && $subcategory == "login_shadow_color" && $name == "text" || $category == "theme" && $subcategory == "login_background_color" && $name == "text" || $category == "theme" && $subcategory == "domain_color" && $name == "text" || $category == "theme" && $subcategory == "domain_shadow_color" && $name == "text" || $category == "theme" && $subcategory == "domain_background_color" && $name == "text" || $category == "theme" && $subcategory == "footer_color" && $name == "text" || $category == "theme" && $subcategory == "footer_background_color" && $name == "text" || $category == "theme" && $subcategory == "message_default_background_color" && $name == "text" || $category == "theme" && $subcategory == "message_default_color" && $name == "text" || $category == "theme" && $subcategory == "message_negative_background_color" && $name == "text" || $category == "theme" && $subcategory == "message_negative_color" && $name == "text" || $category == "theme" && $subcategory == "message_alert_background_color" && $name == "text" || $category == "theme" && $subcategory == "message_alert_color" && $name == "text") {
    echo "\t<style>";
                    } elseif ($_POST['eid' . $id] >= 10000 && $_POST['eid' . $id] <= 99999) {
                        $eid = ltrim($_POST['eid' . $id], "0");
                    } else {
                        $eid = $_POST['eid' . $id];
                    }
                    $entries_updated[] = number_pad($_POST['eid' . $id], 6);
                } else {
                    if ($_POST['eid' . $id] < 9) {
                        $eid = ltrim($_POST['eid' . $id], "000");
                    } elseif ($_POST['eid' . $id] >= 10 && $_POST['eid' . $id] <= 99) {
                        $eid = ltrim($_POST['eid' . $id], "00");
                    } elseif ($_POST['eid' . $id] >= 100 && $_POST['eid' . $id] <= 999) {
                        $eid = ltrim($_POST['eid' . $id], "0");
                    } else {
                        $eid = $_POST['eid' . $id];
                    }
                    $entries_updated[] = number_pad($_POST['eid' . $id], 4);
                }
                if ($_POST['brewPaid' . $id] == 1) {
                    $brewPaid = 1;
                } else {
                    $brewPaid = $row_enum['brewPaid'];
                }
                $updateSQL = sprintf("UPDATE %s SET brewReceived='1', brewJudgingNumber='%s', brewBoxNum='%s', brewPaid='%s' WHERE id='%s';", $brewing_db_table, $judging_number, $_POST['box' . $id], $brewPaid, $eid);
                $result = mysql_query($updateSQL, $brewing) or die(mysql_error());
                //echo $updateSQL."<br>";
            }
        }
    }
    $entry_list .= display_array_content($entries_updated, 2);
}
 $nopesananrasmi = strtoupper(mysql_real_escape_string($_POST['nopesananrasmi']));
 $tempohjaminan = strtoupper(mysql_real_escape_string($_POST['tempohjaminan']));
 $pembekal = mysql_real_escape_string($_POST['pembekal']);
 $catID = explode("-", $kategori);
 $kategoriID = $catID[0];
 $kategoriKod = $catID[1];
 $catSubID = explode("-", $subkategori);
 $kategoriSubID = $catSubID[0];
 $kategoriSubKod = $catSubID[1];
 $jnsID = explode("-", $jenis);
 $jenisID = $jnsID[0];
 $jenisKod = $jnsID[1];
 $year4digit = date("Y");
 $year2digit = date("y");
 $number = $db->get_counter_barcode($year4digit);
 $generateIncrement = number_pad($number, 4);
 //KK = Kod Kementerian
 //BKP10 = Kod Bahagian
 //H/I = H - Harta Modal  I - Harta Inventori
 //07 = Tahun perolehan aset
 //0001 = Bil atau nombor siri aset
 //001002003 = kod klasifikasi (kategori+sub kategori+jenis)
 //DB|SB|LH|HD = Kaedah Perolehan
 //$nosiripendaftaran = "KK/BKP10/H/07/0001/001002003/HD";
 $nosiripendaftaran = "KK/BKP10/H/{$year2digit}/{$generateIncrement}/{$kategoriKod}{$kategoriSubKod}{$jenisKod}/{$kaedahperolehan}";
 //echo '<br/>'.print_r($_POST);
 $tarikhterimaFormat = changeDateBeginYear($tarikhterima);
 $updateHartaModal = "UPDATE  hartamodal set kaedah_peroleh='{$kaedahperolehan}', no_siri_daftar='{$nosiripendaftaran}', kementerian='{$kementerian}',\r\n\t\t\t\t\t\t\t\tbahagian='{$bahagian}',kod_nasional='{$kodnasional}',kategori_id='{$kategoriID}',sub_kategori_id='{$kategoriSubID}',jenis_id='{$jenisID}',\r\n\t\t\t\t\t\t\t\tbuatan='{$buatan}',jenis_no_enjin='{$jenisnoenjin}',no_casis='{$siripembuat}',no_pendaftaran='{$nodaftarkenderaan}',komponen='{$komponen}',\r\n\t\t\t\t\t\t\t\tharga_perolehan_asal='{$hargaasal}',tarikh_terima='{$tarikhterimaFormat}',no_pesanan='{$nopesananrasmi}',\ttempoh_jaminan='{$tempohjaminan}',\t\t\t\t\r\n\t\t\t\t\t\t\t\tpembekal_id='{$pembekal}' where id='{$IdHartaModal}' ";
 $result = $db->sql_query($updateHartaModal);
 if ($result) {
     //	Display success
function get_date($startdate, $enddate)
{
    global $warnings;
    $node = '';
    $start_gYear = '';
    $end_gYear = '';
    //validate dates
    if ($startdate != 0 && is_int($startdate) && $startdate < 3000) {
        $start_gYear = number_pad($startdate, 4);
    }
    if ($enddate != 0 && is_int($enddate) && $enddate < 3000) {
        $end_gYear = number_pad($enddate, 4);
    }
    if ($startdate == 0 && $enddate != 0) {
        $node = '<date' . (strlen($end_gYear) > 0 ? ' standardDate="' . $end_gYear . '"' : '') . '>' . get_date_textual($enddate) . '</date>';
    } elseif ($startdate != 0 && $enddate == 0) {
        $node = '<date' . (strlen($start_gYear) > 0 ? ' standardDate="' . $start_gYear . '"' : '') . '>' . get_date_textual($startdate) . '</date>';
    } elseif ($startdate == $enddate) {
        $node = '<date' . (strlen($end_gYear) > 0 ? ' standardDate="' . $end_gYear . '"' : '') . '>' . get_date_textual($enddate) . '</date>';
    } elseif ($startdate != 0 && $enddate != 0) {
        $node = '<dateRange><fromDate' . (strlen($start_gYear) > 0 ? ' standardDate="' . $start_gYear . '"' : '') . '>' . get_date_textual($startdate) . '</fromDate><toDate' . (strlen($start_gYear) > 0 ? ' standardDate="' . $end_gYear . '"' : '') . '>' . get_date_textual($enddate) . '</toDate></dateRange>';
    }
    return $node;
}
function generate_nuds($row)
{
    global $stylesheet;
    global $deities;
    $recordId = 'price.' . $row['Price no.'];
    if ($row['Material'] != 'vacat') {
        $doc = new XMLWriter();
        //$doc->openUri('php://output');
        $doc->openUri('nuds/' . $recordId . '.xml');
        $doc->setIndent(true);
        //now we need to define our Indent string,which is basically how many blank spaces we want to have for the indent
        $doc->setIndentString("    ");
        $doc->startDocument('1.0', 'UTF-8');
        $doc->startElement('nuds');
        $doc->writeAttribute('xmlns', 'http://nomisma.org/nuds');
        $doc->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
        $doc->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
        $doc->writeAttribute('recordType', 'conceptual');
        //control
        $doc->startElement('control');
        $doc->writeElement('recordId', $recordId);
        $doc->writeElement('publicationStatus', 'approved');
        $doc->startElement('maintenanceAgency');
        $doc->writeElement('agencyName', 'American Numismatic Society');
        $doc->endElement();
        $doc->writeElement('maintenanceStatus', 'derived');
        //maintenanceHistory
        $doc->startElement('maintenanceHistory');
        $doc->startElement('maintenanceEvent');
        $doc->writeElement('eventType', 'derived');
        $doc->startElement('eventDateTime');
        $doc->writeAttribute('standardDateTime', date(DATE_W3C));
        $doc->text(date(DATE_RFC2822));
        $doc->endElement();
        $doc->writeElement('agentType', 'machine');
        $doc->writeElement('agent', 'PHP');
        $doc->writeElement('eventDescription', 'Generated from CSV fro Google Drive.');
        $doc->endElement();
        $doc->endElement();
        //semanticDeclaration
        $doc->startElement('semanticDeclaration');
        $doc->writeElement('prefix', 'dcterms');
        $doc->writeElement('namespace', 'http://purl.org/dc/terms/');
        $doc->endElement();
        $doc->startElement('semanticDeclaration');
        $doc->writeElement('prefix', 'nmo');
        $doc->writeElement('namespace', 'http://nomisma.org/ontology#');
        $doc->endElement();
        //rightsStmt
        $doc->startElement('rightsStmt');
        $doc->writeElement('copyrightHolder', 'American Numismatic Society');
        $doc->startElement('license');
        $doc->writeAttribute('xlink:type', 'simple');
        $doc->writeAttribute('xlink:href', 'http://opendatacommons.org/licenses/odbl/');
        $doc->endElement();
        $doc->endElement();
        $doc->endElement();
        //descMeta
        $doc->startElement('descMeta');
        //generate title
        $title = "Price {$row['Price no.']}";
        $doc->startElement('title');
        $doc->writeAttribute('xml:lang', 'en');
        $doc->text($title);
        $doc->endElement();
        /***** TYPEDESC *****/
        $doc->startElement('typeDesc');
        //objectType
        $doc->startElement('objectType');
        $doc->writeAttribute('xlink:type', 'simple');
        $doc->writeAttribute('xlink:href', 'http://nomisma.org/id/coin');
        $doc->text('Coin');
        $doc->endElement();
        //manufacture
        $doc->startElement('manufacture');
        $doc->writeAttribute('xlink:type', 'simple');
        $doc->writeAttribute('xlink:href', 'http://nomisma.org/id/struck');
        $doc->text('Struck');
        $doc->endElement();
        if (strlen($row['Material']) > 0) {
            $vals = explode('|', $row['Material']);
            foreach ($vals as $val) {
                if (substr($val, -1) == '?') {
                    $uri = 'http://nomisma.org/id/' . substr($val, 0, -1);
                    $uncertainty = true;
                    $content = processUri($uri);
                } else {
                    $uri = 'http://nomisma.org/id/' . $val;
                    $uncertainty = false;
                    $content = processUri($uri);
                }
                $doc->startElement($content['element']);
                $doc->writeAttribute('xlink:type', 'simple');
                $doc->writeAttribute('xlink:href', $uri);
                $doc->text($content['label']);
                $doc->endElement();
            }
        }
        if (strlen($row['Denomination']) > 0) {
            $vals = explode('|', $row['Denomination']);
            foreach ($vals as $val) {
                $uri = 'http://nomisma.org/id/' . $val;
                $uncertainty = false;
                $content = processUri($uri);
                $doc->startElement($content['element']);
                $doc->writeAttribute('xlink:type', 'simple');
                $doc->writeAttribute('xlink:href', $uri);
                $doc->text($content['label']);
                $doc->endElement();
            }
        }
        if (is_numeric($row['From Date']) && is_numeric($row['To Date'])) {
            if ($row['From Date'] == $row['To Date']) {
                $doc->startElement('date');
                $doc->writeAttribute('standardDate', number_pad($row['From Date'], 4));
                $doc->text(abs(intval($row['From Date'])) . ' B.C.');
                $doc->endElement();
            } else {
                $doc->startElement('dateRange');
                $doc->startElement('fromDate');
                $doc->writeAttribute('standardDate', number_pad($row['From Date'], 4));
                $doc->text(abs(intval($row['From Date'])) . ' B.C.');
                $doc->endElement();
                $doc->startElement('toDate');
                $doc->writeAttribute('standardDate', number_pad($row['To Date'], 4));
                $doc->text(abs(intval($row['To Date'])) . ' B.C.');
                $doc->endElement();
                $doc->endElement();
            }
        }
        //authority
        if (strlen($row['Authority']) > 0 || strlen($row['Stated authority']) > 0 || strlen($row['Magistrate ID 1']) > 0 || strlen($row['Magistrate ID 2']) > 0) {
            $doc->startElement('authority');
            if (strlen($row['Authority']) > 0) {
                $vals = explode('|', $row['Authority']);
                foreach ($vals as $val) {
                    $uri = 'http://nomisma.org/id/' . $val;
                    $uncertainty = false;
                    $content = processUri($uri);
                    $role = 'authority';
                    $doc->startElement($content['element']);
                    $doc->writeAttribute('xlink:type', 'simple');
                    $doc->writeAttribute('xlink:role', $role);
                    $doc->writeAttribute('xlink:href', $uri);
                    if ($uncertainty == true) {
                        $doc->writeAttribute('certainty', 'uncertain');
                    }
                    $doc->text($content['label']);
                    $doc->endElement();
                }
            }
            /*elseif (strlen($row['Mint ID']) > 0 && $row['Mint ID'] != 'uncertain_value'){
            			$vals = explode('|', $row['Mint ID']);
            			foreach ($vals as $val){
            				$uri = 'http://nomisma.org/id/' . $val;
            				$uncertainty = (strtolower(trim($row['Mint Uncertain'])) == 'true' ? true : false);
            				$content = processUri($uri);
            			
            				$doc->startElement('corpname');
            				$doc->writeAttribute('xlink:type', 'simple');
            				$doc->writeAttribute('xlink:role', 'authority');
            				$doc->writeAttribute('xlink:href', $uri);
            				if($uncertainty == true){
            					$doc->writeAttribute('certainty', 'uncertain');
            				}
            				$doc->text($content['label']);
            				$doc->endElement();
            			} 
            		}*/
            if (strlen($row['Stated authority']) > 0) {
                $vals = explode('|', $row['Stated authority']);
                foreach ($vals as $val) {
                    $uri = 'http://nomisma.org/id/' . $val;
                    $uncertainty = false;
                    $content = processUri($uri);
                    $role = 'statedAuthority';
                    $doc->startElement($content['element']);
                    $doc->writeAttribute('xlink:type', 'simple');
                    $doc->writeAttribute('xlink:role', $role);
                    $doc->writeAttribute('xlink:href', $uri);
                    if ($uncertainty == true) {
                        $doc->writeAttribute('certainty', 'uncertain');
                    }
                    $doc->text($content['label']);
                    $doc->endElement();
                }
            }
            //magistrates
            if (strlen($row['Magistrate ID 1']) > 0) {
                $vals = explode('|', $row['Magistrate ID 1']);
                foreach ($vals as $val) {
                    $uri = 'http://nomisma.org/id/' . $val;
                    $uncertainty = false;
                    $content = processUri($uri);
                    $role = 'issuer';
                    $doc->startElement($content['element']);
                    $doc->writeAttribute('xlink:type', 'simple');
                    $doc->writeAttribute('xlink:role', $role);
                    $doc->writeAttribute('xlink:href', $uri);
                    if ($uncertainty == true) {
                        $doc->writeAttribute('certainty', 'uncertain');
                    }
                    $doc->text($content['label']);
                    $doc->endElement();
                }
            }
            if (strlen($row['Magistrate ID 2']) > 0) {
                $vals = explode('|', $row['Magistrate ID 2']);
                foreach ($vals as $val) {
                    $uri = 'http://nomisma.org/id/' . $val;
                    $uncertainty = false;
                    $content = processUri($uri);
                    $role = 'issuer';
                    $doc->startElement($content['element']);
                    $doc->writeAttribute('xlink:type', 'simple');
                    $doc->writeAttribute('xlink:role', $role);
                    $doc->writeAttribute('xlink:href', $uri);
                    if ($uncertainty == true) {
                        $doc->writeAttribute('certainty', 'uncertain');
                    }
                    $doc->text($content['label']);
                    $doc->endElement();
                }
            }
            $doc->endElement();
        }
        //geography
        //mint
        if (strlen($row['Mint ID']) > 0 || strlen($row['Region']) > 0) {
            $doc->startElement('geographic');
            if (strlen($row['Mint ID']) > 0) {
                $vals = explode('|', $row['Mint ID']);
                foreach ($vals as $val) {
                    $uri = 'http://nomisma.org/id/' . $val;
                    $uncertainty = strtolower(trim($row['Mint Uncertain'])) == 'true' ? true : false;
                    $content = processUri($uri);
                    $doc->startElement('geogname');
                    $doc->writeAttribute('xlink:type', 'simple');
                    $doc->writeAttribute('xlink:role', 'mint');
                    $doc->writeAttribute('xlink:href', $uri);
                    if ($uncertainty == true) {
                        $doc->writeAttribute('certainty', 'uncertain');
                    }
                    $doc->text($content['label']);
                    $doc->endElement();
                }
                //regions extracted at the point of indexing in Numishare
                /*if (isset($content['parent'])){
                			$orgs[] = $content['parent'];
                			$parentArray = processUri($content['parent']);
                			$role = 'region';
                			$doc->startElement($parentArray['element']);
                				$doc->writeAttribute('xlink:type', 'simple');
                				$doc->writeAttribute('xlink:role', $role);
                				$doc->writeAttribute('xlink:href', $content['parent']);
                				$doc->text($parentArray['label']);
                			$doc->endElement();
                		}*/
            }
            if (strlen($row['Region']) > 0) {
                $vals = explode('|', $row['Region']);
                foreach ($vals as $val) {
                    $uri = 'http://nomisma.org/id/' . $val;
                    $uncertainty = strtolower(trim($row['Region Uncertain'])) == 'true' ? true : false;
                    $content = processUri($uri);
                    $doc->startElement($content['element']);
                    $doc->writeAttribute('xlink:type', 'simple');
                    $doc->writeAttribute('xlink:role', 'region');
                    $doc->writeAttribute('xlink:href', $uri);
                    if ($uncertainty == true) {
                        $doc->writeAttribute('certainty', 'uncertain');
                    }
                    $doc->text($content['label']);
                    $doc->endElement();
                }
            }
            $doc->endElement();
        }
        //obverse
        if (strlen($row['O']) > 0) {
            $doc->startElement('obverse');
            $key = trim($row['O']);
            $type = '';
            $doc->startElement('type');
            foreach ($stylesheet as $desc) {
                if ($desc['Abbreviation'] == $key) {
                    $type = $desc['en'];
                    foreach ($desc as $k => $v) {
                        if ($k != 'Abbreviation') {
                            $doc->startElement('description');
                            $doc->writeAttribute('xml:lang', $k);
                            $doc->text(trim($v));
                            $doc->endElement();
                        }
                    }
                    break;
                }
            }
            $doc->endElement();
            //deity
            foreach ($deities as $deity) {
                if (strstr($deity['name'], ' ') !== FALSE) {
                    //haystack is string when the deity is multiple words
                    $haystack = strtolower(trim($type));
                    if (strstr($haystack, strtolower($deity['matches'])) !== FALSE) {
                        $bm_uri = strlen($deity['bm_uri']) > 0 ? ' xlink:href="' . $deity['bm_uri'] . '"' : '';
                        $doc->startElement('persname');
                        $doc->writeAttribute('xlink:type', 'simple');
                        $doc->writeAttribute('xlink:role', 'deity');
                        if (strlen($deity['bm_uri']) > 0) {
                            $doc->writeAttribute('xlink:href', $deity['bm_uri']);
                        }
                        $doc->text($deity['name']);
                        $doc->endElement();
                    }
                } else {
                    //haystack is array
                    $string = preg_replace('/[^a-z]+/i', ' ', trim($type));
                    $haystack = explode(' ', $string);
                    if (in_array($deity['matches'], $haystack)) {
                        $doc->startElement('persname');
                        $doc->writeAttribute('xlink:type', 'simple');
                        $doc->writeAttribute('xlink:role', 'deity');
                        if (strlen($deity['bm_uri']) > 0) {
                            $doc->writeAttribute('xlink:href', $deity['bm_uri']);
                        }
                        $doc->text($deity['name']);
                        $doc->endElement();
                    }
                }
            }
            //symbols
            if (strlen($row['Ο: to l.']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'leftField');
                $doc->text(trim($row['Ο: to l.']));
                $doc->endElement();
            }
            if (strlen($row['O: to r.']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'rightField');
                $doc->text(trim($row['O: to r.']));
                $doc->endElement();
            }
            if (strlen($row['O:below']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'below');
                $doc->text(trim($row['O:below']));
                $doc->endElement();
            }
            if (strlen($row['O:Scalp']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'scalp');
                $doc->text(trim($row['O:Scalp']));
                $doc->endElement();
            }
            $doc->endElement();
        }
        //reverse
        if (strlen($row['R']) > 0 || strlen($row['R Legend']) > 0) {
            $doc->startElement('reverse');
            $key = trim($row['R']);
            $type = '';
            $doc->startElement('type');
            foreach ($stylesheet as $desc) {
                if ($desc['Abbreviation'] == $key) {
                    $type = $desc['en'];
                    foreach ($desc as $k => $v) {
                        if ($k != 'Abbreviation') {
                            $doc->startElement('description');
                            $doc->writeAttribute('xml:lang', $k);
                            $doc->text(trim($v));
                            $doc->endElement();
                        }
                    }
                    break;
                }
            }
            $doc->endElement();
            //deity
            foreach ($deities as $deity) {
                if (strstr($deity['name'], ' ') !== FALSE) {
                    //haystack is string when the deity is multiple words
                    $haystack = strtolower(trim($type));
                    if (strstr($haystack, strtolower($deity['matches'])) !== FALSE) {
                        $bm_uri = strlen($deity['bm_uri']) > 0 ? ' xlink:href="' . $deity['bm_uri'] . '"' : '';
                        $doc->startElement('persname');
                        $doc->writeAttribute('xlink:type', 'simple');
                        $doc->writeAttribute('xlink:role', 'deity');
                        if (strlen($deity['bm_uri']) > 0) {
                            $doc->writeAttribute('xlink:href', $deity['bm_uri']);
                        }
                        $doc->text($deity['name']);
                        $doc->endElement();
                    }
                } else {
                    //haystack is array
                    $string = preg_replace('/[^a-z]+/i', ' ', trim($type));
                    $haystack = explode(' ', $string);
                    if (in_array($deity['matches'], $haystack)) {
                        $doc->startElement('persname');
                        $doc->writeAttribute('xlink:type', 'simple');
                        $doc->writeAttribute('xlink:role', 'deity');
                        if (strlen($deity['bm_uri']) > 0) {
                            $doc->writeAttribute('xlink:href', $deity['bm_uri']);
                        }
                        $doc->text($deity['name']);
                        $doc->endElement();
                    }
                }
            }
            //legend
            if (strlen($row['R Legend']) > 0) {
                $doc->startElement('legend');
                $doc->writeAttribute('scriptCode', 'Grek');
                $doc->text(trim($row['R Legend']));
                $doc->endElement();
            }
            //symbols
            if (strlen($row['<LF>1']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'leftField');
                $doc->text(trim($row['<LF>1']));
                $doc->endElement();
            }
            if (strlen($row['<LF>2']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'leftField');
                $doc->text(trim($row['<LF>2']));
                $doc->endElement();
            }
            if (strlen($row['<LF>3']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'leftField');
                $doc->text(trim($row['<LF>3']));
                $doc->endElement();
            }
            if (strlen($row['<LF>4']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'leftField');
                $doc->text(trim($row['<LF>4']));
                $doc->endElement();
            }
            if (strlen($row['<TH>1']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'beneathThrone');
                $doc->text(trim($row['<TH>1']));
                $doc->endElement();
            }
            if (strlen($row['<TH>2']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'beneathThrone');
                $doc->text(trim($row['<TH>2']));
                $doc->endElement();
            }
            if (strlen($row['<TH>3']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'beneathThrone');
                $doc->text(trim($row['<TH>3']));
                $doc->endElement();
            }
            if (strlen($row['<EX>1']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'exergue');
                $doc->text(trim($row['<EX>1']));
                $doc->endElement();
            }
            if (strlen($row['<EX>2']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'exergue');
                $doc->text(trim($row['<EX>2']));
                $doc->endElement();
            }
            if (strlen($row['<EX>3']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'exergue');
                $doc->text(trim($row['<EX>3']));
                $doc->endElement();
            }
            if (strlen($row['<RF>1']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'rightField');
                $doc->text(trim($row['<RF>1']));
                $doc->endElement();
            }
            if (strlen($row['<RF>2']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'rightField');
                $doc->text(trim($row['<RF>2']));
                $doc->endElement();
            }
            if (strlen($row['Above1']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'above');
                $doc->text(trim($row['Above1']));
                $doc->endElement();
            }
            if (strlen($row['Above2']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'above');
                $doc->text(trim($row['Above2']));
                $doc->endElement();
            }
            if (strlen($row['Below1']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'below');
                $doc->text(trim($row['Below1']));
                $doc->endElement();
            }
            if (strlen($row['Below2']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'below');
                $doc->text(trim($row['Below2']));
                $doc->endElement();
            }
            if (strlen($row['<LW>1']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'leftWing');
                $doc->text(trim($row['<LW>1']));
                $doc->endElement();
            }
            if (strlen($row['<LW>2']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'leftWing');
                $doc->text(trim($row['<LW>2']));
                $doc->endElement();
            }
            if (strlen($row['<RW>1']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'rightWing');
                $doc->text(trim($row['<RW>1']));
                $doc->endElement();
            }
            if (strlen($row['<RW>2']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'rightWing');
                $doc->text(trim($row['<RW>2']));
                $doc->endElement();
            }
            if (strlen($row['Between']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'between');
                $doc->text(trim($row['Between']));
                $doc->endElement();
            }
            if (strlen($row['Boss']) > 0) {
                $doc->startElement('symbol');
                $doc->writeAttribute('position', 'boss');
                $doc->text(trim($row['Boss']));
                $doc->endElement();
            }
            $doc->endElement();
        }
        //end typeDesc
        $doc->endElement();
        //refDesc
        $doc->startElement('refDesc');
        $doc->startElement('reference');
        $doc->writeAttribute('xlink:type', 'simple');
        $doc->writeAttribute('xlink:href', 'http://nomisma.org/id/price1991');
        $doc->writeAttribute('semantic', 'dcterms:source');
        $doc->text('Price (1991)');
        $doc->endElement();
        $doc->endElement();
        //end descMeta
        $doc->endElement();
        //end nuds
        $doc->endElement();
        $doc->endDocument();
        echo "Writing {$recordId}\n";
    } else {
        "Ignoring vacat: {$recordId}\n";
    }
}
            if (strlen(trim($row['dynasty'])) > 0) {
                $writer->startElement('org:organization');
                $writer->writeAttribute('rdf:resource', trim($row['dynasty']));
                $writer->endElement();
            }
            //dates
            if (is_numeric($row['fromDate2'])) {
                $writer->startElement('nmo:hasStartDate');
                $writer->writeAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#gYear');
                $writer->text(number_pad(trim($row['fromDate2']), 4));
                $writer->endElement();
            }
            if (is_numeric($row['toDate2'])) {
                $writer->startElement('nmo:hasEndDate');
                $writer->writeAttribute('rdf:datatype', 'http://www.w3.org/2001/XMLSchema#gYear');
                $writer->text(number_pad(trim($row['toDate2']), 4));
                $writer->endElement();
            }
            $writer->endElement();
        }
        $writer->endElement();
        $writer->endDocument();
        $writer->flush();
        echo "Wrote {$row['nomisma_id']}\n";
    }
}
//create list of ids
/*$list = '';
foreach ($data as $row){
	if (strlen(trim($row['nomisma_id'])) > 0){
		$list .= "{$row['nomisma_id']}\n";
$usf = generate_json('coins.csv', true);
$data = generate_json('ric_severan.csv', false);
$deityMatchArray = get_deity_array();
$csv = "Nomisma.org id,Emperor/Authority,Authority URI,Mint,Mint URI,Online Example,Group,Obverse Type,Obverse Legend,Obverse notes,Reverse Type,Reverse Legend,Reverse notes,From Date,To Date,Denomination,Denomination URI,Material,Material URI,Obverse Portrait,Obverse Portrait URI,Reverse Portrait,Reverse Portrait URI,Obverse Deity,Reverse Deity,Issuer,Magistrate,Region,Region URI,Locality,Locality uri,New Region,New Region URI,Object Type URI,Source\n";
foreach ($data as $row) {
    $id = $row['Nomisma.org id'];
    $auth_uri = $row['Nomisma URI for Authority'];
    $array = $usf[$id];
    $fromDate = '';
    $toDate = '';
    $dates = explode('-', $array['sdate']);
    if (strlen($dates[0]) > 0) {
        $fromDate = number_pad($dates[0], 4);
    }
    if (strlen($dates[1]) > 0) {
        $toDate = number_pad($dates[1], 4);
    }
    //get mint uri
    switch ($row['Mint']) {
        case 'Rome':
            $mint_uri = 'http://nomisma.org/id/rome';
            $region_uri = 'http://nomisma.org/id/latium';
            break;
        case 'Alexandria':
            $mint_uri = 'http://nomisma.org/id/alexandreia_egypt';
            $region_uri = 'http://nomisma.org/id/egypt';
            break;
        case 'Emesa':
            $mint_uri = 'http://nomisma.org/id/emisa';
            $region_uri = 'http://nomisma.org/id/syria';
            break;
function generate_nuds($row, $files)
{
    $recordId = $row['recordId'];
    $orgs = array();
    //parse references
    if (strlen($row['reference']) > 0) {
        //strip obverse and reverse descriptions out if possible
        preg_match('/(Obverse:?.*)Reverse/', $row['reference'], $obverse);
        preg_match('/(Reverse:?.*)$/', $row['reference'], $reverse);
        if (isset($obverse[1]) || isset($reverse[1])) {
            $refText = trim(str_replace($reverse[1], '', str_replace($obverse[1], '', $row['reference'])));
        } else {
            $refText = trim($row['reference']);
        }
    }
    $doc = new XMLWriter();
    //$doc->openUri('php://output');
    $doc->openUri('nuds/' . $recordId . '.xml');
    $doc->setIndent(true);
    //now we need to define our Indent string,which is basically how many blank spaces we want to have for the indent
    $doc->setIndentString("    ");
    $doc->startDocument('1.0', 'UTF-8');
    $doc->startElement('nuds');
    $doc->writeAttribute('xmlns', 'http://nomisma.org/nuds');
    $doc->writeAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
    $doc->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
    $doc->writeAttribute('xmlns:mets', 'http://www.loc.gov/METS/');
    $doc->writeAttribute('recordType', 'physical');
    //control
    $doc->startElement('control');
    $doc->writeElement('recordId', $recordId);
    $doc->writeElement('publicationStatus', 'approved');
    $doc->startElement('maintenanceAgency');
    $doc->writeElement('agencyName', 'American Numismatic Society');
    $doc->endElement();
    $doc->writeElement('maintenanceStatus', 'derived');
    //maintenanceHistory
    $doc->startElement('maintenanceHistory');
    $doc->startElement('maintenanceEvent');
    $doc->writeElement('eventType', 'derived');
    $doc->startElement('eventDateTime');
    $doc->writeAttribute('standardDateTime', date(DATE_W3C));
    $doc->text(date(DATE_RFC2822));
    $doc->endElement();
    $doc->writeElement('agentType', 'machine');
    $doc->writeElement('agent', 'PHP');
    $doc->writeElement('eventDescription', 'Generated from CSV, after iterative cleanup process (including Open Refine)');
    $doc->endElement();
    $doc->endElement();
    //rightsStmt
    $doc->startElement('rightsStmt');
    $doc->writeElement('copyrightHolder', 'American Numismatic Society');
    $doc->startElement('license');
    $doc->writeAttribute('xlink:type', 'simple');
    $doc->writeAttribute('xlink:href', 'http://opendatacommons.org/licenses/odbl/');
    $doc->endElement();
    $doc->endElement();
    $doc->endElement();
    //descMeta
    $doc->startElement('descMeta');
    //generate title
    $objectType = processUri($row['objectType']);
    $auth = array();
    if (strlen($row['authorityPerson']) > 0) {
        $auth[] = processUri($row['authorityPerson']);
        $auth[0]['certain'] = true;
    } else {
        if (strlen($row['org']) > 0) {
            $vals = explode('|', $row['org']);
            $i = 0;
            foreach ($vals as $val) {
                if (substr($val, -1) == '?') {
                    $uri = substr($val, 0, -1);
                    $auth[] = processUri($uri);
                    $auth[$i]['certain'] = false;
                } else {
                    $uri = $val;
                    $auth[] = processUri($uri);
                    $auth[$i]['certain'] = true;
                }
                $i++;
            }
        }
    }
    //english
    $title = $objectType['label'] . ' - ';
    $authFragment = array();
    foreach ($auth as $v) {
        $authFragment[] = $v['label'] . ($v['certain'] == false ? '?' : '');
    }
    $title .= implode('/', $authFragment) . ', ';
    if (strlen($row['dob_ah']) > 0) {
        $title .= 'AH ' . $row['dob_ah'] . ' / ';
    }
    if (strlen($row['fromDate']) > 0 && strlen($row['toDate']) > 0) {
        $title .= 'CE ';
        if ($row['fromDate'] == $row['toDate']) {
            $title .= $row['fromDate'];
        } else {
            $title .= $row['fromDate'] . '-' . $row['toDate'];
        }
    }
    if (strlen($row['dob_ah']) > 0 || strlen($row['fromDate']) > 0 && strlen($row['toDate']) > 0) {
        $title .= '. ';
    }
    $title .= $recordId;
    $doc->startElement('title');
    $doc->writeAttribute('xml:lang', 'en');
    $doc->text($title);
    $doc->endElement();
    //arabic
    $title = $recordId;
    if (strlen($row['dob_ah']) > 0 || strlen($row['fromDate']) > 0 && strlen($row['toDate']) > 0) {
        $title .= ' .';
    }
    if (strlen($row['fromDate']) > 0 && strlen($row['toDate']) > 0) {
        if ($row['fromDate'] == $row['toDate']) {
            $title .= $row['fromDate'];
        } else {
            $title .= $row['toDate'] . '-' . $row['fromDate'];
        }
        $title .= ' CE';
    }
    if (strlen($row['dob_ah']) > 0) {
        $title .= ' \\ ' . $row['dob_ah'];
    }
    $authFragment = array();
    foreach ($auth as $v) {
        $authFragment[] = ($v['certain'] == false ? '؟' : '') . $v['ar'];
    }
    $title .= ' ،' . implode('/', $authFragment);
    $title .= ' - ' . $objectType['ar'];
    $doc->startElement('title');
    $doc->writeAttribute('xml:lang', 'ar');
    $doc->text($title);
    $doc->endElement();
    /***** TYPEDESC *****/
    $doc->startElement('typeDesc');
    //objectType
    if (strlen($row['objectType']) > 0) {
        $vals = explode('|', $row['objectType']);
        foreach ($vals as $val) {
            if (substr($val, -1) == '?') {
                $uri = substr($val, 0, -1);
                $uncertainty = true;
                $content = processUri($uri);
            } else {
                $uri = $val;
                $uncertainty = false;
                $content = processUri($uri);
            }
            $doc->startElement($content['element']);
            $doc->writeAttribute('xlink:type', 'simple');
            $doc->writeAttribute('xlink:href', $uri);
            if ($uncertainty == true) {
                $doc->writeAttribute('certainty', 'uncertain');
            }
            $doc->text($content['label']);
            $doc->endElement();
        }
    }
    if (strlen($row['material']) > 0) {
        $vals = explode('|', $row['material']);
        foreach ($vals as $val) {
            if (substr($val, -1) == '?') {
                $uri = substr($val, 0, -1);
                $uncertainty = true;
                $content = processUri($uri);
            } else {
                $uri = $val;
                $uncertainty = false;
                $content = processUri($uri);
            }
            $doc->startElement($content['element']);
            $doc->writeAttribute('xlink:type', 'simple');
            $doc->writeAttribute('xlink:href', $uri);
            if ($uncertainty == true || $row['materialUncertainty'] == 'true') {
                $doc->writeAttribute('certainty', 'uncertain');
            }
            $doc->text($content['label']);
            $doc->endElement();
        }
    }
    if (strlen($row['manufacture']) > 0) {
        $vals = explode('|', $row['manufacture']);
        foreach ($vals as $val) {
            if (substr($val, -1) == '?') {
                $uri = substr($val, 0, -1);
                $uncertainty = true;
                $content = processUri($uri);
            } else {
                $uri = $val;
                $uncertainty = false;
                $content = processUri($uri);
            }
            $doc->startElement($content['element']);
            $doc->writeAttribute('xlink:type', 'simple');
            $doc->writeAttribute('xlink:href', $uri);
            if ($uncertainty == true) {
                $doc->writeAttribute('certainty', 'uncertain');
            }
            $doc->text($content['label']);
            $doc->endElement();
        }
    }
    if (is_numeric($row['fromDate']) && is_numeric($row['toDate'])) {
        if ($row['fromDate'] == $row['toDate']) {
            $doc->startElement('date');
            $doc->writeAttribute('standardDate', number_pad($row['fromDate'], 4));
            $doc->text($row['fromDate']);
            $doc->endElement();
        } else {
            $doc->startElement('dateRange');
            $doc->startElement('fromDate');
            $doc->writeAttribute('standardDate', number_pad($row['fromDate'], 4));
            $doc->text($row['fromDate']);
            $doc->endElement();
            $doc->startElement('toDate');
            $doc->writeAttribute('standardDate', number_pad($row['toDate'], 4));
            $doc->text($row['toDate']);
            $doc->endElement();
            $doc->endElement();
        }
    }
    //date on object
    if (strlen($row['dob_ah']) > 0) {
        $doc->startElement('dateOnObject');
        $doc->writeAttribute('calendar', 'ah');
        $doc->text($row['dob_ah']);
        $doc->endElement();
    }
    if (strlen($row['dob']) > 0) {
        $doc->writeElement('dateOnObject', $row['dob']);
    }
    //authority
    if (strlen($row['authorityPerson']) > 0 || strlen($row['org']) > 0 || strlen($row['otherPerson']) > 0) {
        $doc->startElement('authority');
        if (strlen($row['org']) > 0 && (strlen($row['authorityPerson']) == 0 && strlen($row['otherPerson']) == 0)) {
            $vals = explode('|', $row['org']);
            foreach ($vals as $val) {
                if (substr($val, -1) == '?') {
                    $uri = substr($val, 0, -1);
                    $uncertainty = true;
                    $content = processUri($uri);
                } else {
                    $uri = $val;
                    $uncertainty = false;
                    $content = processUri($uri);
                }
                $role = 'authorizingEntity';
                $doc->startElement($content['element']);
                $doc->writeAttribute('xlink:type', 'simple');
                $doc->writeAttribute('xlink:role', $role);
                $doc->writeAttribute('xlink:href', $uri);
                if ($uncertainty == true) {
                    $doc->writeAttribute('certainty', 'uncertain');
                }
                $doc->text($content['label']);
                $doc->endElement();
            }
        }
        if (strlen($row['authorityPerson']) > 0) {
            $vals = explode('|', $row['authorityPerson']);
            foreach ($vals as $val) {
                if (substr($val, -1) == '?') {
                    $uri = substr($val, 0, -1);
                    $uncertainty = true;
                    $content = processUri($uri);
                } else {
                    $uri = $val;
                    $uncertainty = false;
                    $content = processUri($uri);
                }
                $doc->startElement($content['element']);
                $doc->writeAttribute('xlink:type', 'simple');
                $doc->writeAttribute('xlink:role', 'authority');
                $doc->writeAttribute('xlink:href', $uri);
                if ($uncertainty == true) {
                    $doc->writeAttribute('certainty', 'uncertain');
                }
                $doc->text($content['label']);
                $doc->endElement();
                //if there is a dynasty or org
                if (isset($content['parent'])) {
                    $orgs[] = $content['parent'];
                    $parentArray = processUri($content['parent']);
                    $role = 'authorizingEntity';
                    $doc->startElement($parentArray['element']);
                    $doc->writeAttribute('xlink:type', 'simple');
                    $doc->writeAttribute('xlink:role', $role);
                    $doc->writeAttribute('xlink:href', $content['parent']);
                    $doc->text($parentArray['label']);
                    $doc->endElement();
                }
            }
        }
        if (strlen($row['otherPerson']) > 0) {
            $vals = explode('|', $row['otherPerson']);
            foreach ($vals as $val) {
                if (substr($val, -1) == '?') {
                    $uri = substr($val, 0, -1);
                    $uncertainty = true;
                    $content = processUri($uri);
                } else {
                    $uri = $val;
                    $uncertainty = false;
                    $content = processUri($uri);
                }
                $doc->startElement($content['element']);
                $doc->writeAttribute('xlink:type', 'simple');
                $doc->writeAttribute('xlink:href', $uri);
                $doc->writeAttribute('xlink:role', 'authority');
                if ($uncertainty == true) {
                    $doc->writeAttribute('certainty', 'uncertain');
                }
                $doc->text($content['label']);
                $doc->endElement();
                //if there is a dynasty or org; only insert if there isn't already one
                if (isset($content['parent'])) {
                    if (!in_array($content['parent'], $orgs)) {
                        $parentArray = processUri($content['parent']);
                        $role = 'authorizingEntity';
                        $doc->startElement($parentArray['element']);
                        $doc->writeAttribute('xlink:type', 'simple');
                        $doc->writeAttribute('xlink:role', $role);
                        $doc->writeAttribute('xlink:href', $content['parent']);
                        $doc->text($parentArray['label']);
                        $doc->endElement();
                    }
                }
            }
        }
        //add Muluk al-Tawaif
        if ($recordId >= 1633 && $recordId <= 1636) {
            $doc->startElement('corpname');
            $doc->writeAttribute('xlink:type', 'simple');
            $doc->writeAttribute('xlink:role', 'authorizingEntity');
            $doc->writeAttribute('xlink:href', 'http://nomisma.org/id/muluk_al-tawaif');
            $doc->text('Muluk al-Tawaif');
            $doc->endElement();
        }
        $doc->endElement();
    }
    //geography
    //mint
    if (strlen($row['mint']) > 0) {
        $doc->startElement('geographic');
        $vals = explode('|', $row['mint']);
        foreach ($vals as $val) {
            if (substr($val, -1) == '?') {
                $uri = substr($val, 0, -1);
                $uncertainty = true;
                $content = processUri($uri);
            } else {
                $uri = $val;
                $uncertainty = false;
                $content = processUri($uri);
            }
            $doc->startElement($content['element']);
            $doc->writeAttribute('xlink:type', 'simple');
            $doc->writeAttribute('xlink:role', 'mint');
            $doc->writeAttribute('xlink:href', $uri);
            if ($uncertainty == true) {
                $doc->writeAttribute('certainty', 'uncertain');
            }
            $doc->text($content['label']);
            $doc->endElement();
        }
        $doc->endElement();
    }
    //obverse
    if (isset($obverse[1])) {
        $doc->startElement('obverse');
        $doc->startElement('type');
        $doc->startElement('description');
        $doc->writeAttribute('xml:lang', 'en');
        $doc->text(trim(str_replace('Obverse:', '', $obverse[1])));
        $doc->endElement();
        $doc->endElement();
        $doc->endElement();
    }
    //reverse
    if (isset($reverse[1])) {
        $doc->startElement('reverse');
        $doc->startElement('type');
        $doc->startElement('description');
        $doc->writeAttribute('xml:lang', 'en');
        $doc->text(trim(str_replace('Reverse:', '', $reverse[1])));
        $doc->endElement();
        $doc->endElement();
        $doc->endElement();
    }
    //end typeDesc
    $doc->endElement();
    /***** PHYSDESC *****/
    $doc->startElement('physDesc');
    //measurementsSet
    if (is_numeric($row['weight']) || is_numeric($row['diameter']) || is_numeric($row['height']) && is_numeric($row['width'])) {
        $doc->startElement('measurementsSet');
        if (strlen($row['weight']) > 0 && is_numeric($row['weight'])) {
            $doc->startElement('weight');
            $doc->writeAttribute('units', 'g');
            $doc->text($row['weight']);
            $doc->endElement();
        }
        if (strlen($row['diameter']) > 0 && is_numeric($row['diameter'])) {
            $doc->startElement('diameter');
            $doc->writeAttribute('units', 'mm');
            $doc->text($row['diameter']);
            $doc->endElement();
        }
        if (strlen($row['height']) > 0 && is_numeric($row['height']) && strlen($row['width']) > 0 && is_numeric($row['width'])) {
            $doc->startElement('height');
            $doc->writeAttribute('units', 'mm');
            $doc->text($row['height']);
            $doc->endElement();
            $doc->startElement('width');
            $doc->writeAttribute('units', 'mm');
            $doc->text($row['width']);
            $doc->endElement();
        }
        $doc->endElement();
    }
    if (strlen($row['authenticity']) > 0) {
        $doc->writeElement('authenticity', $row['authenticity']);
    }
    //end physDesc
    $doc->endElement();
    /***** REFDESC *****/
    if (isset($refText)) {
        if (strlen($refText) > 0) {
            $references = explode(';', $refText);
            $doc->startElement('refDesc');
            foreach ($references as $reference) {
                $doc->writeElement('reference', trim($reference));
            }
            $doc->endElement();
        }
    }
    /***** ADMINDESC *****/
    $doc->startElement('adminDesc');
    $doc->startElement('identifier');
    $doc->writeAttribute('localType', 'catnum');
    $doc->text($recordId);
    $doc->endElement();
    if (strlen($row['regno']) > 0) {
        $doc->startElement('identifier');
        $doc->writeAttribute('localType', 'regno');
        $doc->text($row['regno']);
        $doc->endElement();
    }
    if (strlen($row['1887 catalog number']) > 0) {
        $doc->startElement('identifier');
        $doc->writeAttribute('localType', '1887catnum');
        $doc->text($row['1887 catalog number']);
        $doc->endElement();
    }
    $doc->startElement('collection');
    $doc->writeAttribute('xlink:type', 'simple');
    $doc->writeAttribute('xlink:href', 'http://nomisma.org/id/egyptian_national_library');
    $doc->text('Egyptian National Library');
    $doc->endElement();
    //end adminDesc
    $doc->endElement();
    //note
    if (strlen($row['note']) > 0) {
        $doc->startElement('noteSet');
        $doc->writeElement('note', $row['note']);
        $doc->endElement();
    }
    //end descMeta
    $doc->endElement();
    /***** IMAGES *****/
    $doc->startElement('digRep');
    $doc->startElement('mets:fileSec');
    foreach ($files as $file) {
        if (strpos($file, '.jpg') !== FALSE) {
            $arr = explode('_', str_replace('.jpg', '', $file));
            $id = $arr[0];
            $type = $arr[1];
            if ($id == $recordId) {
                switch ($type) {
                    case 'obv':
                        $use = 'obverse';
                        break;
                    case 'rev':
                        $use = 'reverse';
                        break;
                    default:
                        $use = $type;
                }
                $doc->startElement('mets:fileGrp');
                $doc->writeAttribute('USE', $use);
                //reference image
                $doc->startElement('mets:file');
                $doc->writeAttribute('USE', 'reference');
                $doc->writeAttribute('MIMETYPE', 'image/jpeg');
                $doc->startElement('mets:FLocat');
                $doc->writeAttribute('LOCTYPE', 'URL');
                $doc->writeAttribute('xlink:href', 'media/reference/' . $file);
                $doc->endElement();
                $doc->endElement();
                //display thumbnail for obverse and reverse images only
                if ($use == 'obverse' || $use == 'reverse') {
                    $doc->startElement('mets:file');
                    $doc->writeAttribute('USE', 'thumbnail');
                    $doc->writeAttribute('MIMETYPE', 'image/jpeg');
                    $doc->startElement('mets:FLocat');
                    $doc->writeAttribute('LOCTYPE', 'URL');
                    $doc->writeAttribute('xlink:href', 'media/thumbnail/' . $file);
                    $doc->endElement();
                    $doc->endElement();
                }
                //end mets:fileGrp
                $doc->endElement();
            }
        }
    }
    //end mets:fileSec
    $doc->endElement();
    //end digRep
    $doc->endElement();
    //end nuds
    $doc->endElement();
    $doc->endDocument();
    echo "Writing {$recordId}\n";
}
Ejemplo n.º 15
0
 if ($vars_code && $vars_file) {
     $db_query = mysql_db_query($_MYSQL_BDE, 'SELECT * FROM code_sourcecode WHERE id=' . $vars_code, $db_connect);
     $db_count = mysql_num_rows($db_query);
     if ($db_count != 0) {
         $vars_users = mysql_result($db_query, 0, 'strUser');
         if ($vars_users) {
             $db_querb = @mysql_db_query($_MYSQL_BDE, "SELECT username FROM kod_members WHERE id='{$vars_users}'", $db_connect);
             $db_counb = @mysql_num_rows($db_querb);
             $vars_users = NULL;
             if ($db_counb) {
                 $vars_users = mysql_result($db_querb, 0, 'username');
                 mysql_free_result($db_querb);
             }
         }
         if ($vars_file != -1) {
             $vars_temps = URL_REPS . strtolower($vars_users) . '_sourcepb_' . number_pad(mysql_result($db_query, 0, 'id'), 5) . '.zip';
             $vars_array = unzip($vars_temps, $vars_file);
             if ($vars_array[0] && $vars_array[1]) {
                 header('Content-Description: File Transfer');
                 header('Content-Tranfer-Encoding: none');
                 header('Content-Length: ' . $vars_array[2]);
                 header('Content-Type: application/force-download; name="' . basename(setSpecialChar($vars_array[0])) . '"');
                 header('Content-Disposition: attachment; filename="' . basename(setSpecialChar($vars_array[0])) . '"');
                 echo $vars_array[1];
             }
             mysql_free_result($db_query);
             exit;
         } else {
             $vars_temps = mysql_result($db_query, 0, 'strName');
             header('Content-Description: File Transfer');
             header('Content-Tranfer-Encoding: none');