Пример #1
0
/**	
 * Recursive difference of two arrays
 *	
 * @param array $a1 Array, from which $a2 is subtacted
 * @param array $a2 Array, wich is subtracted from $a1
 *
 * @return array $diff Array, containing elements from $a2, that are not contained in $a1
 *
 */
function arrDiff($a1, $a2)
{
    $diff = array();
    foreach ($a1 as $k => $v) {
        unset($dv);
        if (is_int($k)) {
            // Compare values
            if (in_array($v, $a2) === false and !is_array($v)) {
                $dv = $v;
            } else {
                if (in_array($v, $a2) === false and is_array($v)) {
                    $dv = arrDiff($v, $a2[$k]);
                } else {
                    if ($v === 0 and $a2[$k] !== 0 or $v === '0' and $a2[$k] !== '0') {
                        $dv = $v;
                    }
                }
            }
            if (isset($dv) and $dv != array()) {
                $diff[] = $dv;
            }
        } else {
            // Compare noninteger keys
            if (!$a2[$k] and $a2[$k] != 0 or $v != 0 and $a2[$k] == 0) {
                $dv = $v;
            } else {
                if (is_array($v)) {
                    $dv = arrDiff($v, $a2[$k]);
                } else {
                    if ($a2[$k] != $v) {
                        $dv = $v;
                    }
                }
            }
            if (isset($dv) and $dv != array()) {
                $diff[$k] = $dv;
            }
        }
    }
    return $diff;
}
Пример #2
0
function form_diff_response($c_new, $c_old, $send_all, $redraw)
{
    include 'utils/array_diff.php';
    $c_diff_new = arrDiff($c_new, $c_old);
    $c_diff_old = arrDiff($c_old, $c_new);
    $response = array();
    if ($send_all == 1) {
        $response['in'] = $c_new;
    } else {
        if (count($c_diff_new) > 0) {
            $response['in'] = $c_diff_new;
        }
        if (count($c_diff_old) > 0) {
            $response['out'] = $c_diff_old;
        }
    }
    if ($redraw == 1) {
        $response['in'] = $c_new;
        $response['in']['redraw'] = 1;
    }
    return $response;
}
Пример #3
0
 public function revision($id = "")
 {
     $changed = array();
     $data = array();
     $sql = "select `revisions`.* from `revisions` where `revisions`.`id`='" . mysql_real_escape_string($id) . "' and `revisions`.`table`='investment_orgs' ";
     $q = $this->db->query($sql);
     $revision = $q->result_array();
     $revision = $revision[0];
     if ($revision['id']) {
         $investment_org_id = $revision['ipc_id'];
         $investment_org = json_decode($revision['json_data']);
         $investment_org = objectToArray($investment_org);
         $sql = "select * from `investment_orgs` where `id`=" . $this->db->escape($investment_org_id);
         $q = $this->db->query($sql);
         $investment_orgtemp = $q->result_array();
         $sql = "select * from `web_users` where `id`=" . $this->db->escape($revision['web_user_id']);
         $q = $this->db->query($sql);
         $web_user = $q->result_array();
         $web_user = $web_user[0];
         $web_user = getWebUser($web_user);
         $data['web_user'] = $web_user;
     }
     if ($investment_orgtemp[0]['id'] && $web_user) {
         $corig = $this->edit($investment_orgtemp[0]['id'], true);
         //get original data
         $data['investment_orgorig'] = $investment_orgtemp[0];
         $data['revision'] = $revision;
         $categories = $corig['categories'];
         $funding_rounds = $corig['funding_rounds'];
         $currencies = $corig['currencies'];
         $countries = $corig['countries'];
         $milestones = $corig['milestones'];
         $competitors = $corig['competitors'];
         $data['categories'] = $categories;
         $data['funding_rounds'] = $funding_rounds;
         $data['currencies'] = $currencies;
         $data['countries'] = $countries;
         $data['milestones'] = $milestones;
         $data['competitors'] = $competitors;
         if (arrDiff($corig['competitors'], $data['competitors'])) {
             $changed[] = 'competitors';
         }
         $people = array();
         if (is_array($investment_org['p_ids'])) {
             foreach ($investment_org['p_ids'] as $key => $value) {
                 $sql = "select * from `people` where `id`='" . mysql_real_escape_string($value) . "'";
                 $q = $this->db->query($sql);
                 $p = $q->result_array();
                 $p = $p[0];
                 $person = array();
                 $person['investment_org_id'] = $investment_org_id;
                 $person['person_id'] = $value;
                 $person['role'] = $investment_org['p_roles'][$key];
                 $person['start_date'] = $investment_org['p_start_dates'][$key];
                 $person['start_date_ts'] = strtotime($investment_org['p_start_dates'][$key]) . "";
                 $person['end_date'] = $investment_org['p_end_dates'][$key];
                 $person['end_date_ts'] = strtotime($investment_org['p_end_dates'][$key]) + 0 . "";
                 $person['name'] = $p['name'];
                 //$person['slug'] = $p['slug'];
                 $people[] = $person;
             }
         }
         $data['people'] = $people;
         //remove ids and edn_date_ts2
         foreach ($corig['people'] as $key => $value) {
             unset($corig['people'][$key]['id']);
             unset($corig['people'][$key]['end_date_ts2']);
         }
         $a = bubble_sort($data['people'], "name", "asc", true);
         $b = bubble_sort($corig['people'], "name", "asc", true);
         if (arrDiff($a, $b)) {
             $changed[] = "people";
         }
         //remove arrays
         $unsets = array();
         foreach ($investment_org as $key => $value) {
             if (is_array($value)) {
                 $unsets[] = $key;
             } else {
                 if (trim($value) != trim($corig['investment_org'][$key])) {
                     $changed[] = $key;
                 }
             }
         }
         foreach ($unsets as $key) {
             unset($investment_org[$key]);
         }
         $data['investment_org'] = $investment_org;
         $data['changed'] = $changed;
         $data['content'] = $this->load->view('investment_orgs/add', $data, true);
         $this->load->view('layout/main', $data);
     }
 }
Пример #4
0
 public function revision($id = "")
 {
     $changed = array();
     $data = array();
     $sql = "select `revisions`.* from `revisions` where `revisions`.`id`='" . mysql_real_escape_string($id) . "' and `revisions`.`table`='companies' ";
     $q = $this->db->query($sql);
     $revision = $q->result_array();
     $revision = $revision[0];
     if ($revision['id']) {
         $company_id = $revision['ipc_id'];
         $company = json_decode($revision['json_data']);
         $company = objectToArray($company);
         $sql = "select * from `companies` where `id`=" . $this->db->escape($company_id);
         $q = $this->db->query($sql);
         $companytemp = $q->result_array();
         $sql = "select * from `web_users` where `id`=" . $this->db->escape($revision['web_user_id']);
         $q = $this->db->query($sql);
         $web_user = $q->result_array();
         $web_user = $web_user[0];
         $web_user = getWebUser($web_user);
         $data['web_user'] = $web_user;
     }
     if ($companytemp[0]['id'] && $web_user) {
         $corig = $this->edit($companytemp[0]['id'], true);
         //get original data
         $data['companyorig'] = $companytemp[0];
         $data['revision'] = $revision;
         $categories = $corig['categories'];
         $funding_rounds = $corig['funding_rounds'];
         $currencies = $corig['currencies'];
         $countries = $corig['countries'];
         $milestones = $corig['milestones'];
         $competitors = $corig['competitors'];
         $data['categories'] = $categories;
         $data['funding_rounds'] = $funding_rounds;
         $data['currencies'] = $currencies;
         $data['countries'] = $countries;
         $data['milestones'] = $milestones;
         $data['competitors'] = $competitors;
         if (arrDiff($corig['competitors'], $data['competitors'])) {
             $changed[] = 'competitors';
         }
         $company_fundings = array();
         if (is_array($company['f_rounds'])) {
             foreach ($company['f_rounds'] as $key => $value) {
                 $company_funding = array();
                 $company_funding['round'] = $value;
                 $company_funding['company_id'] = $company_id;
                 $company_funding['currency'] = $company['f_currencies'][$key];
                 $company_funding['amount'] = number_format($company['f_fund_amounts'][$key], "4", ".", "") . "";
                 //must format amount
                 $company_funding['amount_public'] = $company['f_fund_amount_public'][$key] * 1;
                 $company_funding['date'] = $company['f_dates'][$key];
                 $company_funding['date_ts'] = strtotime($company['f_dates'][$key]) . "";
                 //stringify the thing
                 $company_funding['companies'] = array();
                 if (is_array($company['f_companies' . $key])) {
                     foreach ($company['f_companies' . $key] as $k => $v) {
                         $c = array();
                         $c['name'] = $v;
                         //$c['slug'] =
                         $c['id'] = $company['f_company_vals' . $key][$k];
                         $company_funding['companies'][] = $c;
                     }
                 }
                 $company_funding['people'] = array();
                 if (is_array($company['f_people' . $key])) {
                     foreach ($company['f_people' . $key] as $k => $v) {
                         $c = array();
                         $c['name'] = $v;
                         //$c['slug'] =
                         $c['id'] = $company['f_person_vals' . $key][$k];
                         $company_funding['people'][] = $c;
                     }
                 }
                 $company_funding['investment_orgs'] = array();
                 if (is_array($company['f_investment_orgs' . $key])) {
                     foreach ($company['f_investment_orgs' . $key] as $k => $v) {
                         $c = array();
                         $c['name'] = $v;
                         //$c['slug'] =
                         $c['id'] = $company['f_investment_org_vals' . $key][$k];
                         $company_funding['investment_orgs'][] = $c;
                     }
                 }
                 $company_fundings[] = $company_funding;
             }
         }
         $data['company_fundings'] = $company_fundings;
         //check if there are changes
         //remove ids
         foreach ($corig['company_fundings'] as $key => $value) {
             unset($corig['company_fundings'][$key]['id']);
         }
         if (arrDiff($corig['company_fundings'], $data['company_fundings'])) {
             $changed[] = 'company_fundings';
         }
         $people = array();
         if (is_array($company['p_ids'])) {
             foreach ($company['p_ids'] as $key => $value) {
                 $sql = "select * from `people` where `id`='" . mysql_real_escape_string($value) . "'";
                 $q = $this->db->query($sql);
                 $p = $q->result_array();
                 $p = $p[0];
                 $person = array();
                 $person['company_id'] = $company_id;
                 $person['person_id'] = $value;
                 $person['role'] = $company['p_roles'][$key];
                 $person['start_date'] = $company['p_start_dates'][$key];
                 $person['start_date_ts'] = strtotime($company['p_start_dates'][$key]) . "";
                 $person['end_date'] = $company['p_end_dates'][$key];
                 $person['end_date_ts'] = strtotime($company['p_end_dates'][$key]) + 0 . "";
                 $person['name'] = $p['name'];
                 //$person['slug'] = $p['slug'];
                 $people[] = $person;
             }
         }
         $data['people'] = $people;
         //remove ids and edn_date_ts2
         foreach ($corig['people'] as $key => $value) {
             unset($corig['people'][$key]['id']);
             unset($corig['people'][$key]['end_date_ts2']);
         }
         if (arrDiff($data['people'], $corig['people'])) {
             $changed[] = "people";
         }
         $screenshots = array();
         if (is_array($company['screenshots'])) {
             foreach ($company['screenshots'] as $key => $value) {
                 $screenshot = array();
                 $screenshot['company_id'] = $company_id;
                 $screenshot['screenshot'] = $value;
                 $screenshot['title'] = $company['screenshot_titles'][$key];
                 $screenshots[] = $screenshot;
             }
         }
         $data['screenshots'] = $screenshots;
         //remove ids
         foreach ($corig['screenshots'] as $key => $value) {
             unset($corig['screenshots'][$key]['id']);
         }
         if (arrDiff($data['screenshots'], $corig['screenshots'])) {
             $changed[] = 'screenshots';
         }
         $co_categories = $company['categories'];
         $data['co_categories'] = $co_categories;
         if (is_array($data['co_categories']) && is_array($corig['co_categories'])) {
             sort($data['co_categories']);
             sort($corig['co_categories']);
             if (arrDiff($data['co_categories'], $corig['co_categories'])) {
                 $changed[] = 'co_categories';
             }
         }
         //remove arrays
         $unsets = array();
         foreach ($company as $key => $value) {
             if (is_array($value)) {
                 $unsets[] = $key;
             } else {
                 if (trim($value) != trim($corig['company'][$key])) {
                     $changed[] = $key;
                 }
             }
         }
         foreach ($unsets as $key) {
             unset($company[$key]);
         }
         $data['company'] = $company;
         $data['changed'] = $changed;
         $data['content'] = $this->load->view('companies/add', $data, true);
         $this->load->view('layout/main', $data);
     }
 }