예제 #1
0
파일: mysql.php 프로젝트: oliverhale/Cream
 public function Save($data = null)
 {
     if (!$data) {
         return false;
     }
     $sql = "REPLACE INTO " . $this->name . " SET ";
     $set_sql = array();
     $columns = $this->getTableStructure();
     foreach ($columns as $column) {
         $availableColumns[$column['Field']] = 1;
         if ($column['Key'] == 'PRI') {
             $primaryKey = $column['Field'];
         }
     }
     foreach ($data as $key => $value) {
         if (isset($availableColumns[$key])) {
             $set_sql[] = "`" . $key . "`='" . $this->SaveReformating($key, $value) . "'";
         }
     }
     if (!isset($data[$primaryKey])) {
         $set_sql[] = "`" . $primaryKey . "`='" . createGUID() . "'";
     }
     $sql .= implode(",", $set_sql);
     echo $sql;
     $this->Query($sql);
 }
if (!$modx->hasPermission('new_module')) {
    $modx->webAlertAndQuit($_lang["error_no_privileges"]);
}
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id == 0) {
    $modx->webAlertAndQuit($_lang["error_no_id"]);
}
// create globally unique identifiers (guid)
function createGUID()
{
    srand((double) microtime() * 1000000);
    $r = rand();
    $u = uniqid(getmypid() . $r . (double) microtime() * 1000000, 1);
    $m = md5($u);
    return $m;
}
// duplicate module
$newid = $modx->db->insert(array('name' => '', 'description' => '', 'disabled' => '', 'category' => '', 'wrap' => '', 'icon' => '', 'enable_resource' => '', 'resourcefile' => '', 'createdon' => '', 'editedon' => '', 'guid' => '', 'enable_sharedparams' => '', 'properties' => '', 'modulecode' => ''), $modx->getFullTableName('site_modules'), "CONCAT('Duplicate of ',name) AS name, description, disabled, category, wrap, icon, enable_resource, resourcefile, createdon, editedon, '" . createGUID() . "' as guid, enable_sharedparams, properties, modulecode", $modx->getFullTableName('site_modules'), "id='{$id}'");
// Copy from
// duplicate module dependencies
$modx->db->insert(array('module' => '', 'resource' => '', 'type' => ''), $modx->getFullTableName('site_module_depobj'), "'{$newid}', resource, type", $modx->getFullTableName('site_module_depobj'), "module='{$id}'");
// Copy from
// duplicate module user group access
$modx->db->insert(array('module' => '', 'usergroup' => ''), $modx->getFullTableName('site_module_access'), "'{$newid}', usergroup", $modx->getFullTableName('site_module_access'), "module='{$id}'");
// Copy from
// Set the item name for logger
$name = $modx->db->getValue($modx->db->select('name', $modx->getFullTableName('site_modules'), "id='{$newid}'"));
$_SESSION['itemname'] = $name;
// finish duplicating - redirect to new module
$header = "Location: index.php?r=2&a=108&id={$newid}";
header($header);
    <!-- Configuration -->
    <div class="tab-page" id="tabConfig">
        <h2 class="tab"><?php 
echo $_lang['settings_config'];
?>
</h2>
        <script type="text/javascript">tp.addTabPage( document.getElementById( "tabConfig" ) );</script>

        <table width="90%" border="0" cellspacing="0" cellpadding="0">
            <tr><td align="left" valign="top"><?php 
echo $_lang['guid'];
?>
:</td>
                <td align="left" valign="top"><input name="guid" type="text" maxlength="32" value="<?php 
echo (int) $_REQUEST['a'] == 107 ? createGUID() : $content['guid'];
?>
" class="inputBox" onchange="documentDirty=true;" /><br /><br /></td></tr>
            <tr><td align="left" valign="top"><input name="enable_sharedparams" type="checkbox"<?php 
echo $content['enable_sharedparams'] == 1 ? ' checked="checked"' : '';
?>
 class="inputBox" onclick="documentDirty=true;" /> <span style="cursor:pointer" onclick="document.mutate.enable_sharedparams.click();"><?php 
echo $_lang['enable_sharedparams'];
?>
:</span></td>
                <td align="left" valign="top"><span ><span class="comment"><?php 
echo $_lang['enable_sharedparams_msg'];
?>
</span></span><br /><br /></td></tr>
            <tr><td align="left" valign="top"><?php 
echo $_lang['module_config'];
    $e->setError(3);
    $e->dumpError();
}
$id = $_GET['id'];
// create globally unique identifiers (guid)
function createGUID()
{
    srand((double) microtime() * 1000000);
    $r = rand();
    $u = uniqid(getmypid() . $r . (double) microtime() * 1000000, 1);
    $m = md5($u);
    return $m;
}
// duplicate module
if (version_compare(mysql_get_server_info(), "4.0.14") >= 0) {
    $sql = "INSERT INTO " . $modx->getFullTableName("site_modules") . " (name, description, disabled, category, wrap, icon, enable_resource, resourcefile, createdon, editedon, guid, enable_sharedparams, properties, modulecode) \n\t\t\tSELECT CONCAT('Duplicate of ',name) AS 'name', description, disabled, category, wrap, icon, enable_resource, resourcefile, createdon, editedon, '" . createGUID() . "' as 'guid', enable_sharedparams, properties, modulecode \n\t\t\tFROM " . $modx->getFullTableName("site_modules") . " WHERE id={$id};";
    $rs = mysql_query($sql);
} else {
    $sql = "SELECT CONCAT('Duplicate of ',name) AS 'name', description, disabled, category, wrap, icon, enable_resource, resourcefile, createdon, editedon, guid, enable_sharedparams, properties, modulecode \n\t\t\tFROM " . $modx->getFullTableName("site_modules") . " WHERE id={$id};";
    $rs = mysql_query($sql);
    if ($rs) {
        $row = mysql_fetch_assoc($rs);
        $sql = "INSERT INTO " . $modx->getFullTableName("site_modules") . " \n\t\t\t\t(name, description, disabled, category, wrap, icon, enable_resource, resourcefile, createdon, editedon, guid, enable_sharedparams, properties, modulecode) VALUES \n\t\t\t\t('" . $modx->db->escape($row['name']) . "', '" . $modx->db->escape($row['description']) . "', " . $row['disabled'] . ", '" . $row['category'] . "', '" . $row['wrap'] . "', '" . $modx->db->escape($row['icon']) . "', '" . $modx->db->escape($row['enable_resource']) . "', '" . $modx->db->escape($row['resourcefile']) . "', '" . $row['createdon'] . "', '" . $row['editedon'] . "', '" . createGuid() . "', '" . $modx->db->escape($row['enable_sharedparams']) . "', '" . $modx->db->escape($row['properties']) . "', '" . $modx->db->escape($row['modulecode']) . "');";
        $rs = mysql_query($sql);
    }
}
if ($rs) {
    $newid = mysql_insert_id();
} else {
    echo "A database error occured while trying to duplicate module: <br /><br />" . mysql_error();
    exit;
    ?>
 class="inputBox" /> <span style="cursor:pointer" onclick="document.mutate.enable_sharedparams.click();"><?php 
    echo $_lang['enable_sharedparams'];
    ?>
:</span></td>
		</tr>
		<tr class="sharedparams" <?php 
    echo $display;
    ?>
>
			<td align="left" valign="top"><?php 
    echo $_lang['guid'];
    ?>
:</td>
			<td align="left" valign="top"><input name="guid" type="text" maxlength="32" value="<?php 
    echo $content['guid'] != '' ? $content['guid'] : createGUID();
    ?>
" class="inputBox" /><br />
			<span class="comment"><?php 
    echo $_lang['enable_sharedparams_msg'];
    ?>
</span><br /></td>
		</tr>
	</table>
	</div>
	<div class="sectionBody sharedparams" <?php 
    echo $display;
    ?>
>
		<p><?php 
    echo $_lang['module_viewdepend_msg'];
예제 #6
0
function build_wp_mf_maker()
{
    global $wpdb;
    //first empty existing tables
    $sql = "Truncate Table wp_mf_entity;";
    $wpdb->get_results($sql);
    $sql = "Truncate Table wp_mf_maker;";
    $wpdb->get_results($sql);
    $sql = "Truncate Table wp_mf_maker_to_entity;";
    $wpdb->get_results($sql);
    $crossRef = buildCrossRef();
    //retrieve data
    $sql = "SELECT detail.lead_id, lead.form_id, detail.field_number, detail.value, lead.status, wp_mf_faire.faire, detail_long.value as descLong \n            FROM wp_rg_lead lead join wp_rg_lead_detail detail on lead.id = detail.lead_id and lead.status != 'trash' left outer JOIN wp_rg_lead_detail_long detail_long ON (detail.id = detail_long.lead_detail_id) join wp_mf_faire on FIND_IN_SET (detail.form_id, wp_mf_faire.form_ids)> 0";
    $dataArray = array();
    $leadArray = array();
    foreach ($wpdb->get_results($sql) as $row) {
        //build array of leads
        $dataArray[$row->form_id][$row->lead_id][$row->field_number] = $row->value;
        if (isset($row->descLong) && $row->descLong != NULL) {
            $dataArray[$row->form_id][$row->lead_id][$row->field_number] = $row->descLong;
        }
        $dataArray[$row->form_id][$row->lead_id]['data'] = array('status' => $row->status, 'faire' => $row->faire);
    }
    $x = 0;
    $m = 0;
    foreach ($dataArray as $form_id => $formEntries) {
        foreach ($formEntries as $key => $lead) {
            $faire = $lead['data']['faire'];
            $status = isset($lead[$crossRef['wp_mf_entity_array']['status']]) ? $lead[$crossRef['wp_mf_entity_array']['status']] : '';
            //ensure field 303 is set
            if ($status != '') {
                //build array of categories
                $leadCategory = array();
                $MAD = 0;
                foreach ($lead as $leadKey => $leadValue) {
                    //4 additional categories
                    $pos = strpos($leadKey, '321');
                    if ($pos !== false) {
                        $leadCategory[] = $leadValue;
                    }
                    //main catgory
                    $pos = strpos($leadKey, '320');
                    if ($pos !== false) {
                        $leadCategory[] = $leadValue;
                    }
                    //check the flag field 304
                    $pos = strpos($leadKey, '304');
                    if ($pos !== false) {
                        if ($leadValue == 'Mobile App Discover') {
                            $MAD = 1;
                        }
                    }
                }
                //verify we only have unique categories
                $leadCategory = array_unique($leadCategory);
                $catList = implode(',', $leadCategory);
                //build wp_mf_entity table
                $presentationType = isset($lead[$crossRef['wp_mf_entity_array']['presentation_type']]) ? esc_sql($lead[$crossRef['wp_mf_entity_array']['presentation_type']]) : '';
                $presentationTitle = isset($lead[$crossRef['wp_mf_entity_array']['presentation_title']]) ? esc_sql($lead[$crossRef['wp_mf_entity_array']['presentation_title']]) : '';
                $specialRequest = isset($lead[$crossRef['wp_mf_entity_array']['special_request']]) ? esc_sql($lead[$crossRef['wp_mf_entity_array']['special_request']]) : '';
                $onSitePhone = isset($lead[$crossRef['wp_mf_entity_array']['OnsitePhone']]) ? esc_sql($lead[$crossRef['wp_mf_entity_array']['OnsitePhone']]) : '';
                $descShort = isset($lead[$crossRef['wp_mf_entity_array']['desc_short']]) ? esc_sql($lead[$crossRef['wp_mf_entity_array']['desc_short']]) : '';
                $descLong = isset($lead[$crossRef['wp_mf_entity_array']['desc_long']]) ? esc_sql($lead[$crossRef['wp_mf_entity_array']['desc_long']]) : '';
                $projectPhoto = isset($lead[$crossRef['wp_mf_entity_array']['project_photo']]) ? esc_sql($lead[$crossRef['wp_mf_entity_array']['project_photo']]) : '';
                $wp_mf_entitysql = "insert into wp_mf_entity " . "    (lead_id, presentation_title, presentation_type, special_request, " . "     OnsitePhone, desc_short, desc_long, project_photo, status,category,faire,mobile_app_discover) " . " VALUES ('" . $key . "'," . ' "' . $presentationTitle . '", ' . ' "' . $presentationType . '", ' . ' "' . $specialRequest . '", ' . ' "' . $onSitePhone . '", ' . ' "' . $descShort . '", ' . ' "' . $descLong . '", ' . ' "' . $projectPhoto . '", ' . ' "' . $status . '", ' . ' "' . $catList . '", ' . ' "' . $faire . '", ' . '  ' . $MAD . ') ';
                $x++;
                $wpdb->get_results($wp_mf_entitysql);
                if ($wpdb->insert_id == false) {
                    echo 'error inserting record wp_mf_entity:' . $wp_mf_entitysql . '<br/><br/>';
                    $entityID = 0;
                }
                //build wp_mf_maker table (up to 10 rows)
                foreach ($crossRef['wp_mf_maker_array'] as $type => $typeArray) {
                    $fNameLoc = (string) $typeArray['First Name'];
                    //if first name is set for this type and the field numer is set in the returned table data, then use this data else use a blank
                    $firstName = isset($typeArray['First Name']) && isset($lead[$fNameLoc]) ? esc_sql($lead[$fNameLoc]) : '';
                    $lNameLoc = (string) $typeArray['Last Name'];
                    //if first name is set for this type and the field numer is set in the returned table data, then use this data else use a blank
                    $lastName = isset($typeArray['Last Name']) && isset($lead[$lNameLoc]) ? esc_sql($lead[$lNameLoc]) : '';
                    //we need to have at least 1 presenter.  if these fields are empty, pull from the contact info
                    if (trim($firstName) == '' && trim($lastName) == '') {
                        if ($type == 'presenter') {
                            $fNameLoc = (string) $crossRef['wp_mf_maker_array']['contact']['First Name'];
                            //if first name is set for this type and the field numer is set in the returned table data, then use this data else use a blank
                            $firstName = isset($crossRef['wp_mf_maker_array']['contact']['First Name']) && isset($lead[$fNameLoc]) ? esc_sql($lead[$fNameLoc]) : '';
                            $lNameLoc = (string) $crossRef['wp_mf_maker_array']['contact']['Last Name'];
                            //if first name is set for this type and the field numer is set in the returned table data, then use this data else use a blank
                            $lastName = isset($crossRef['wp_mf_maker_array']['contact']['Last Name']) && isset($lead[$lNameLoc]) ? esc_sql($lead[$lNameLoc]) : '';
                            $bio = isset($crossRef['wp_mf_maker_array']['contact']['Bio']) && isset($lead[$crossRef['wp_mf_maker_array']['contact']['Bio']]) ? esc_sql($lead[$crossRef['wp_mf_maker_array']['contact']['Bio']]) : '';
                            $email = isset($crossRef['wp_mf_maker_array']['contact']['Email']) && isset($lead[$crossRef['wp_mf_maker_array']['contact']['Email']]) ? esc_sql($lead[$crossRef['wp_mf_maker_array']['contact']['Email']]) : '';
                            $phone = isset($crossRef['wp_mf_maker_array']['contact']['phone']) && isset($lead[$crossRef['wp_mf_maker_array']['contact']['phone']]) ? esc_sql($lead[$crossRef['wp_mf_maker_array']['contact']['phone']]) : '';
                            $twitter = isset($crossRef['wp_mf_maker_array']['contact']['TWITTER']) && isset($lead[$crossRef['wp_mf_maker_array']['contact']['TWITTER']]) ? esc_sql($lead[$crossRef['wp_mf_maker_array']['contact']['TWITTER']]) : '';
                            $photo = isset($crossRef['wp_mf_maker_array']['contact']['Photo']) && isset($lead[$crossRef['wp_mf_maker_array']['contact']['Photo']]) ? esc_sql($lead[$crossRef['wp_mf_maker_array']['contact']['Photo']]) : '';
                            $website = isset($crossRef['wp_mf_maker_array']['contact']['website']) && isset($lead[$crossRef['wp_mf_maker_array']['contact']['website']]) ? esc_sql($lead[$crossRef['wp_mf_maker_array']['contact']['website']]) : '';
                            $guid = createGUID($key . '-' . $crossRef['wp_mf_maker_array']['contact']['identifier']);
                        }
                    }
                    if (trim($firstName) == '' && trim($lastName) == '') {
                        //don't write the record, no maker here
                    } else {
                        $bio = isset($typeArray['Bio']) && isset($lead[$typeArray['Bio']]) ? esc_sql($lead[$typeArray['Bio']]) : '';
                        $email = isset($typeArray['Email']) && isset($lead[$typeArray['Email']]) ? esc_sql($lead[$typeArray['Email']]) : '';
                        $phone = isset($typeArray['phone']) && isset($lead[$typeArray['phone']]) ? esc_sql($lead[$typeArray['phone']]) : '';
                        $twitter = isset($typeArray['TWITTER']) && isset($lead[$typeArray['TWITTER']]) ? esc_sql($lead[$typeArray['TWITTER']]) : '';
                        $photo = isset($typeArray['Photo']) && isset($lead[$typeArray['Photo']]) ? esc_sql($lead[$typeArray['Photo']]) : '';
                        $website = isset($typeArray['website']) && isset($lead[$typeArray['website']]) ? esc_sql($lead[$typeArray['website']]) : '';
                        $guid = createGUID($key . '-' . $typeArray['identifier']);
                        $wp_mf_makersql = "INSERT INTO wp_mf_maker(lead_id, `First Name`, `Last Name`, `Bio`, `Email`, `phone`, " . " `TWITTER`,  `form_id`, `maker_id`, `Photo`, `website`) " . " VALUES (" . $key . ", '" . $firstName . "','" . $lastName . "','" . $bio . "','" . $email . "', '" . $phone . "'," . " '" . $twitter . "', " . $form_id . ",'" . $guid . "','" . $photo . "','" . $website . "')";
                        $wpdb->get_results($wp_mf_makersql);
                        if ($wpdb->insert_id == false) {
                            echo 'error inserting record wp_mf_maker:' . $wp_mf_makersql . '<br/><br/>';
                        }
                        $m++;
                        //build maker to entity table
                        $wp_mf_maker_to_entity = "INSERT INTO `wp_mf_maker_to_entity`" . " (`maker_id`, `entity_id`, `maker_type`) " . ' VALUES ("' . $guid . '",' . $key . ',"' . $type . '")';
                        $wpdb->get_results($wp_mf_maker_to_entity);
                        if ($wpdb->insert_id == false) {
                            echo 'error inserting record wp_mf_maker_to_entity:' . $wp_mf_maker_to_entity . '<br/><br/>';
                        }
                    }
                }
            }
            //end check field 303 status
        }
    }
    echo 'added ' . $x . ' entity records<br/>';
    echo 'added ' . $m . ' maker records<br/>';
}
<?php

if (!defined('IN_MANAGER_MODE') || IN_MANAGER_MODE != 'true') {
    exit;
}
if (!$modx->hasPermission('new_module')) {
    $e->setError(3);
    $e->dumpError();
}
$id = $_GET['id'];
// duplicate module
$tbl_site_modules = $modx->getFullTableName('site_modules');
$tpl = $_lang['duplicate_title_string'];
$sql = "INSERT INTO {$tbl_site_modules} (name, description, disabled, category, wrap, icon, enable_resource, resourcefile, createdon, editedon, guid, enable_sharedparams, properties, modulecode) \n\t\tSELECT REPLACE('{$tpl}','[+title+]',name) AS 'name', description, disabled, category, wrap, icon, enable_resource, resourcefile, createdon, editedon, '" . createGUID() . "' as 'guid', enable_sharedparams, properties, modulecode \n\t\tFROM {$tbl_site_modules} WHERE id={$id}";
$rs = $modx->db->query($sql);
if ($rs) {
    $newid = $modx->db->getInsertId();
} else {
    echo "A database error occured while trying to duplicate module: <br /><br />" . $modx->db->getLastError();
    exit;
}
// duplicate module dependencies
$tbl_site_module_depobj = $modx->getFullTableName('site_module_depobj');
$sql = "INSERT INTO {$tbl_site_module_depobj} (module, resource, type)\n\t\tSELECT  '{$newid}', resource, type  \n\t\tFROM {$tbl_site_module_depobj} WHERE module={$id}";
$rs = $modx->db->query($sql);
if (!$rs) {
    echo "A database error occured while trying to duplicate module dependencies: <br /><br />" . $modx->db->getLastError();
    exit;
}
// duplicate module user group access
$tbl_site_module_access = $modx->getFullTableName('site_module_access');