<?php

if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__)
        .' is not allowed.' );

/**
 *
 * @package  MediaLibrary
 * @copyright 2021 Andrey Kvasnevskiy-OrdaSoft(akbet@mail.ru); Rob de Cleen(rob@decleen.com);
 * Homepage: https://ordasoft.com
 * @version: 4.6 Free
 * @license GNU General Public license version 2 or later; see LICENSE.txt
 *
 */


class mosMedialibraryOthers {

    /**
     * Sets the parametes for connecting to a webservice via a
     * @param the array of parameters
     * @deprecated $Revision: 1.0 $ - December 2007
     */
    static function setParams(){
        global $medialibrary_configuration;
        $settings = "<?php\n";

        $settings .= "// Do not edit this file. Generated by admin script.\n";
        $settings .= "// MediaLibrary Configuration file\n";
        $settings .= "// General Informations \n";
        $settings .= "\$medialibrary_configuration['release']['version']='" 
                  . $medialibrary_configuration['release']['version'] ."';\n";
        $settings .= "\$medialibrary_configuration['release']['date']='" 
                  . $medialibrary_configuration['release']['date'] ."';\n";
        $settings .= "// edit media \n";
        $settings .= "\$medialibrary_configuration['editmedia']['check']['isbn_asin']='" 
                  . $medialibrary_configuration['editmedia']['check']['isbn_asin']  . "';\n";
        $settings .= "\$medialibrary_configuration['editmedia']['default']['host']='" 
                  . $medialibrary_configuration['editmedia']['default']['host']  . "';\n";
        $settings .= "\$medialibrary_configuration['editmedia']['default']['lang']='" 
                  . $medialibrary_configuration['editmedia']['default']['lang']  . "';\n";
        $settings .= "// price settings\n";
        $settings .= "\$medialibrary_configuration['price']['show']='" 
                  . $medialibrary_configuration['price']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['price']['registrationlevel']='" 
                  . $medialibrary_configuration['price']['registrationlevel'] ."';\n";
        $settings .= "// amazon settings\n";
        $settings .= "\$medialibrary_configuration['ws']['amazon']['tag']='" 
                  . $medialibrary_configuration['ws']['amazon']['tag'] ."';\n";
        $settings .= "\$medialibrary_configuration['ws']['amazon']['devtag']= '"
                  . $medialibrary_configuration['ws']['amazon']['devtag'] ."';\n";
    $settings .= "\$medialibrary_configuration['ws']['amazon']['secret_key']= '" 
              . $medialibrary_configuration['ws']['amazon']['secret_key'] ."';\n";
    $settings .= "// auto increment for mediaid, if 1 - can't add random mediaid \n";
    $settings .= "\$medialibrary_configuration['mediaid']['auto-increment']['boolean']='" 
              . $medialibrary_configuration['mediaid']['auto-increment']['boolean'] ."';\n";
    $settings .= "// fetch images settings\n";
    $settings .= "\$medialibrary_configuration['fetchImages']['boolean']='" 
                  . $medialibrary_configuration['fetchImages']['boolean'] ."';\n";
        $settings .= "\$medialibrary_configuration['fetchImages']['location']='"  
                    . $medialibrary_configuration['fetchImages']['location'] ."';\n";
        $settings .= "// review settings\n";
        $settings .= "\$medialibrary_configuration['reviews']['show']='" 
                  . $medialibrary_configuration['reviews']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['reviews']['registrationlevel']='"  
                    . $medialibrary_configuration['reviews']['registrationlevel'] ."';\n";
    $settings .= "// show [ add media ] button frontend\n";

    $settings .= "\$medialibrary_configuration['add']['show']='" 
                  . $medialibrary_configuration['add']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['add']['registrationlevel']='"  
                    . $medialibrary_configuration['add']['registrationlevel'] ."';\n";


// --------------------------community builder section------------------------

    $settings .= "// show cb_mymedia\n";
    $settings .= "\$medialibrary_configuration['cb_mymedia']['show']='" .
            $medialibrary_configuration['cb_mymedia']['show'] . "';\n";
    $settings .= "\$medialibrary_configuration['cb_mymedia']['registrationlevel']='" .
            $medialibrary_configuration['cb_mymedia']['registrationlevel'] . "';\n";

    $settings .= "// show cb_edit\n";
    $settings .= "\$medialibrary_configuration['cb_edit']['show']='" .
            $medialibrary_configuration['cb_edit']['show'] . "';\n";
    $settings .= "\$medialibrary_configuration['cb_edit']['registrationlevel']='" .
            $medialibrary_configuration['cb_edit']['registrationlevel'] . "';\n";

    $settings .= "// show cb_lend\n";
    $settings .= "\$medialibrary_configuration['cb_lend']['show']='" .
            $medialibrary_configuration['cb_lend']['show'] . "';\n";
    $settings .= "\$medialibrary_configuration['cb_lend']['registrationlevel']='" .
            $medialibrary_configuration['cb_lend']['registrationlevel'] . "';\n";

    $settings .= "// show cb_history\n";
    $settings .= "\$medialibrary_configuration['cb_history']['show']='" .
            $medialibrary_configuration['cb_history']['show'] . "';\n";
    $settings .= "\$medialibrary_configuration['cb_history']['registrationlevel']='" .
            $medialibrary_configuration['cb_history']['registrationlevel'] . "';\n";

// --------------------------end community builder section---------------------

    $settings .= "// lend settings\n";
        $settings .= "\$medialibrary_configuration['lendstatus']['show']='" 
                  . $medialibrary_configuration['lendstatus']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['lendrequest']['registrationlevel']='"  
                    . $medialibrary_configuration['lendrequest']['registrationlevel'] ."';\n";
        $settings .= "// emedia settings\n";



        $settings .= "\$medialibrary_configuration['emedias']['allow']='" 
                  . $medialibrary_configuration['emedias']['allow'] ."';\n";
        $settings .= "\$medialibrary_configuration['emedias']['show']='" 
                  . $medialibrary_configuration['emedias']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['emedias']['registrationlevel']='"  
                    . $medialibrary_configuration['emedias']['registrationlevel'] 
                  ."';\n";
        $settings .= "\$medialibrary_configuration['emedias']['location']='" 
                  . $medialibrary_configuration['emedias']['location'] ."';\n";

    $settings .= "\$medialibrary_configuration['videos_tracks']['allow']='" 
                  . $medialibrary_configuration['videos_tracks']['allow'] ."';\n";
    $settings .= "\$medialibrary_configuration['videos']['location']='" 
                  . $medialibrary_configuration['videos']['location'] ."';\n";
    $settings .= "\$medialibrary_configuration['tracks']['location']='" 
                  . $medialibrary_configuration['tracks']['location'] ."';\n";
    $settings .= "\$medialibrary_configuration['audios']['allow']='" 
                  . $medialibrary_configuration['audios']['allow'] ."';\n";
    $settings .= "\$medialibrary_configuration['audios']['location']='" 
                  . $medialibrary_configuration['audios']['location'] ."';\n";

        $settings .= "// debuging\n";
        $settings .= "\$medialibrary_configuration['debug']='" . $medialibrary_configuration['debug'] . "';\n";
        $settings .= "\$medialibrary_configuration['page']['items']='" 
                  . $medialibrary_configuration['page']['items'] . "';\n";
        $settings .= "\$medialibrary_configuration['people']['items']='" 
                  . $medialibrary_configuration['people']['items'] . "';\n";
        $settings .= "\$medialibrary_configuration['audio_player']['items']='" 
                  . $medialibrary_configuration['audio_player']['items'] . "';\n";
        $settings .= "\$medialibrary_configuration['audio_player']['skin']='" 
                  . $medialibrary_configuration['audio_player']['skin'] . "';\n";
        
        $settings .= "\$medialibrary_configuration['video_player']['items']='" 
                  . $medialibrary_configuration['video_player']['items'] . "';\n";
        $settings .= "\$medialibrary_configuration['video_player']['skin']='" 
                  . $medialibrary_configuration['video_player']['skin'] . "';\n";
        
        $settings .= "// foto size\n";
        $settings .= "\$medialibrary_configuration['author_photo']['show']='" 
                  . $medialibrary_configuration['author_photo']['show'] . "';\n";
        $settings .= "\$medialibrary_configuration['foto']['high']= '" 
                  . $medialibrary_configuration['foto']['high'] ."';\n";
        $settings .= "\$medialibrary_configuration['foto']['width']= '" 
                  . $medialibrary_configuration['foto']['width'] ."';\n";
        $settings .= "\$medialibrary_configuration['foto']['high_author']= '" 
                  . $medialibrary_configuration['foto']['high_author'] . "';\n";
        $settings .= "\$medialibrary_configuration['foto']['width_author']= '" 
                  . $medialibrary_configuration['foto']['width_author'] . "';\n";

        $settings .= "\$medialibrary_configuration['license']['show']='" 
                  . $medialibrary_configuration['license']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['license']['text']= '" 
                  . $medialibrary_configuration['license']['text'] ."';\n";

//*******************   begin add button 'buy now'   ***********************
        $settings .= "// button '[ buy now ]'\n";
        $settings .= "\$medialibrary_configuration['buy_now']['show']='" 
                  . $medialibrary_configuration['buy_now']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['buy_now']['allow']['categories']='"   
                    . $medialibrary_configuration['buy_now']['allow']['categories'] 
                  ."';\n";
//**********   end add button 'buy now'   **************************************


    //*************************   begin add for Advance search  ******************************
    $settings .= "// Advance search \n";
    $settings .= "\$medialibrary_configuration['advsearch']['show']='" 
                  . $medialibrary_configuration['advsearch']['show'] ."';\n";
    $settings .= "\$medialibrary_configuration['advsearch']['registrationlevel']='"   
                    . $medialibrary_configuration['advsearch']['registrationlevel'] ."';\n";
    $settings .= "\$medialibrary_configuration['search_field']['show']='" 
                  . $medialibrary_configuration['search_field']['show'] ."';\n";
    $settings .= "\$medialibrary_configuration['search_field']['registrationlevel']='"  
                     . $medialibrary_configuration['search_field']['registrationlevel'] ."';\n";
    //*****   end add for Advance search  ***********

    //*************************   begin add for merge description  ******************************
    $settings .= "//merge description \n";
    $settings .= "\$medialibrary_configuration['merge_description']['use']='"   
                    . $medialibrary_configuration['merge_description']['use'] ."';\n";
    $settings .= "\$medialibrary_configuration['merge_description']['registrationlevel']='"   
                    . $medialibrary_configuration['merge_description']['registrationlevel'] ."';\n";
    //*****   end add for merge description'  ***********
    //
    // *****  RSS *********
    $settings .= "\$medialibrary_configuration['rss']['show']='" . $medialibrary_configuration['rss']['show'] 
                  ."';\n";
    $settings .= "\$medialibrary_configuration['rss']['registrationlevel']='"   
                    . $medialibrary_configuration['rss']['registrationlevel'] ."';\n";
    // *****  RSS *********
    // *****  PRINT VIEW *********
    $settings .= "\$medialibrary_configuration['print_view']['show']='" 
                  . $medialibrary_configuration['print_view']['show'] ."';\n";
    $settings .= "\$medialibrary_configuration['print_view']['registrationlevel']='"   
                    . $medialibrary_configuration['print_view']['registrationlevel'] ."';\n";
    // *****  PRINT VIEW *********
    // *****  PRINT PDF *********
    $settings .= "\$medialibrary_configuration['print_pdf']['show']='" 
                  . $medialibrary_configuration['print_pdf']['show'] ."';\n";
    $settings .= "\$medialibrary_configuration['print_pdf']['registrationlevel']='"   
                    . $medialibrary_configuration['print_pdf']['registrationlevel'] ."';\n";
    // *****  PRINT PDF *********
    // *****  MAIL TO *********
    $settings .= "\$medialibrary_configuration['mail_to']['show']='" 
                  . $medialibrary_configuration['mail_to']['show'] ."';\n";
    $settings .= "\$medialibrary_configuration['mail_to']['registrationlevel']='"   
                    . $medialibrary_configuration['mail_to']['registrationlevel'] ."';\n";
    // *****  MAIL TO *********
    //
    $settings .= "//view_media\n";
        $settings .= "\$medialibrary_configuration['view_media']='" 
                  . $medialibrary_configuration['view_media'] . "';\n";

//*************************   begin add send mail for admin  ************
        $settings .= "// send email for admin\n";
    $settings .= "\$medialibrary_configuration['review_email']['address']='"   
                    . $medialibrary_configuration['review_email']['address'] ."';\n";      
    $settings .= "\$medialibrary_configuration['review_added_email']['show']='"   
                    . $medialibrary_configuration['review_added_email']['show'] ."';\n";

    $settings .= "\$medialibrary_configuration['review_added_email']['registrationlevel']='"  
                     . $medialibrary_configuration['review_added_email']['registrationlevel'] ."';\n";
    $settings .= "//order_begin \n";

    $settings .= "\$medialibrary_configuration['music_order_type']['show']='"   
                    . $medialibrary_configuration['music_order_type']['show'] ."';\n";

    $settings .= "\$medialibrary_configuration['book_order_type']['show']='" 
                  . $medialibrary_configuration['book_order_type']['show'] ."';\n";

    $settings .= "\$medialibrary_configuration['game_order_type']['show']='"
             . $medialibrary_configuration['game_order_type']['show'] ."';\n";

    $settings .= "\$medialibrary_configuration['video_order_type']['show']='"   
                    . $medialibrary_configuration['video_order_type']['show'] ."';\n";
    $settings .= "\$medialibrary_configuration['all_order_type']['show']='" 
                  . $medialibrary_configuration['all_order_type']['show'] ."';\n";


    $settings .= "//order_end \n\n";

    $settings .= "\$medialibrary_configuration['lendrequest_email']['address']='"   
                    . $medialibrary_configuration['lendrequest_email']['address'] ."';\n";
    $settings .= "\$medialibrary_configuration['lendrequest_email']['show']='"   
                    . $medialibrary_configuration['lendrequest_email']['show'] ."';\n";
    $settings .= "\$medialibrary_configuration['lendrequest_email']['registrationlevel']='"   
                    . $medialibrary_configuration['lendrequest_email']['registrationlevel'] ."';\n";
    $settings .= "//[ Add media ] send email massage \n\n";

    $settings .= "\$medialibrary_configuration['lend_before_end_notify']='" 
                  . $medialibrary_configuration['lend_before_end_notify'] ."';\n";
    $settings .= "\$medialibrary_configuration['lend_before_end_notify_days']='"   
                    . $medialibrary_configuration['lend_before_end_notify_days'] ."';\n";
    $settings .= "\$medialibrary_configuration['lend_before_end_notify_email']='"   
                    . $medialibrary_configuration['lend_before_end_notify_email'] ."';\n";

    $settings .= "\$medialibrary_configuration['add_media_email']['address']='"   
                    . $medialibrary_configuration['add_media_email']['address'] ."';\n";
    $settings .= "\$medialibrary_configuration['add_media_email']['show']='" 
                  . $medialibrary_configuration['add_media_email']['show'] ."';\n";
    $settings .= "\$medialibrary_configuration['add_media_email']['registrationlevel']='"   
                    . $medialibrary_configuration['add_media_email']['registrationlevel'] ."';\n";

//*************************   end add send mail for admin   *************

        //add for show in category picture
        $settings .= "// show in category picture\n";
        $settings .= "\$medialibrary_configuration['cat_pic']['show']='" 
                  . $medialibrary_configuration['cat_pic']['show'] ."';\n";

        //******* Lend Request form******
        $settings .= "\$medialibrary_configuration['lend_answer']='" 
                  . $medialibrary_configuration['lend_answer'] ."';\n";
        $settings .= "\$medialibrary_configuration['lend_form']='" 
                  . $medialibrary_configuration['lend_form'] ."';\n";

   //add for show subcategory
   $settings .= "// show subcategory\n";
   $settings .= "\$medialibrary_configuration['subcategory']['show']='" 
                  . $medialibrary_configuration['subcategory']['show'] ."';\n";

/////////////Proxy Relase
        $settings .= "\$medialibrary_configuration['proxy_server']['address']='"  
                    . $medialibrary_configuration['proxy_server']['address'] ."';\n";
        $settings .= "\$medialibrary_configuration['port_proxy_server']['address']='"  
                     . $medialibrary_configuration['port_proxy_server']['address'] ."';\n";
        $settings .= "\$medialibrary_configuration['login_proxy_server']['address']='"   
                    . $medialibrary_configuration['login_proxy_server']['address'] ."';\n";
        $settings .= "\$medialibrary_configuration['password_proxy_server']['address']='"  
                     . $medialibrary_configuration['password_proxy_server']['address'] ."';\n";

        $settings .= "\$medialibrary_configuration['approve_on_add']['show']='"  
                     . $medialibrary_configuration['approve_on_add']['show'] . "';\n";
        $settings .= "\$medialibrary_configuration['approve_on_add']['registrationlevel']='"   
                    . $medialibrary_configuration['approve_on_add']['registrationlevel'] . "';\n";

        // review approve
        $settings .= "\$medialibrary_configuration['approve_review']['show']='"  
                     . $medialibrary_configuration['approve_review']['show'] . "';\n";
        $settings .= "\$medialibrary_configuration['approve_review']['registrationlevel']='"   
                    . $medialibrary_configuration['approve_review']['registrationlevel'] . "';\n";

        $settings .= "\$medialibrary_configuration['publish_on_add']['show']='"   
                    . $medialibrary_configuration['publish_on_add']['show'] . "';\n";
        $settings .= "\$medialibrary_configuration['publish_on_add']['registrationlevel']='"  
                     . $medialibrary_configuration['publish_on_add']['registrationlevel'] . "';\n";
        $settings .= "\$medialibrary_configuration['edit_someone_media']['show']='"   
                    . $medialibrary_configuration['edit_someone_media']['show'] . "';\n";
        $settings .= "\$medialibrary_configuration['edit_someone_media']['registrationlevel']='"   
                    . $medialibrary_configuration['edit_someone_media']['registrationlevel'] . "';\n";
        $settings .= "\$medialibrary_configuration['litpage']['show']='" 
                  . $medialibrary_configuration['litpage']['show'] . "';\n";
        $settings .= "\$medialibrary_configuration['litpage']['registrationlevel']='"  
                     . $medialibrary_configuration['litpage']['registrationlevel'] . "';\n";
        $settings .= "\$medialibrary_configuration['litpage_author']['show']='"   
                    . $medialibrary_configuration['litpage_author']['show'] . "';\n";
        $settings .= "\$medialibrary_configuration['litpage_author']['registrationlevel']='"   
                    . $medialibrary_configuration['litpage_author']['registrationlevel'] . "';\n";

        $settings .= "//update \n";
        $settings .= "\$medialibrary_configuration['update']='" . $medialibrary_configuration['update'] ."';\n";
        $settings .= "//view type \n";
        $settings .= "\$medialibrary_configuration['view_type']='" 
                  . $medialibrary_configuration['view_type'] ."';\n";
                                    $settings .= "//view type single \n";
        $settings .= "\$medialibrary_configuration['view_type_single']='" 
                  . $medialibrary_configuration['view_type_single'] ."';\n";
                                    $settings .= "//view type video \n";
        $settings .= "\$medialibrary_configuration['view_type_video']='" 
                  . $medialibrary_configuration['view_type_video'] ."';\n";
                    $settings .= "//view type music \n";
    $settings .= "\$medialibrary_configuration['view_type_music']='" 
                  . $medialibrary_configuration['view_type_music'] ."';\n";
                    $settings .= "//view type game \n";
    $settings .= "\$medialibrary_configuration['view_type_game']='" 
                  . $medialibrary_configuration['view_type_game'] ."';\n";
                    $settings .= "//view type book \n";
    $settings .= "\$medialibrary_configuration['view_type_book']='"
                   . $medialibrary_configuration['view_type_book'] ."';\n";

                  $settings .= "//view type all \n";
    $settings .= "\$medialibrary_configuration['view_type_all']='" 
                  . $medialibrary_configuration['view_type_all'] ."';\n";

    $settings .= "//show_search_media\n";
        $settings .= "\$medialibrary_configuration['show_search_media']='" 
                  . $medialibrary_configuration['show_search_media'] . "';\n";
                  $settings .= "//view type display book \n";
    $settings .= "\$medialibrary_configuration['view_type_display_book']='" 
                  . $medialibrary_configuration['view_type_display_book'] ."';\n";
                  $settings .= "//view type display video \n";
    $settings .= "\$medialibrary_configuration['view_type_display_video']='" 
                  . $medialibrary_configuration['view_type_display_video'] ."';\n";
                  $settings .= "//view type display music \n";
    $settings .= "\$medialibrary_configuration['view_type_display_music']='" 
                  . $medialibrary_configuration['view_type_display_music'] ."';\n";
                 $settings .= "//view type display game \n";
    $settings .= "\$medialibrary_configuration['view_type_display_game']='" 
                  . $medialibrary_configuration['view_type_display_game'] ."';\n";
                $settings .= "\$medialibrary_configuration['price_unit_show']='" 
                  . $medialibrary_configuration['price_unit_show'] . "';\n";
        $settings .= "\$medialibrary_configuration['lendrequest_admin_decline_accept']='"   
                    . $medialibrary_configuration['lendrequest_admin_decline_accept'] ."';\n";
        $settings .= "\$medialibrary_configuration['owner']['show']='" 
                  . $medialibrary_configuration['owner']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['currency']='" 
                  . $medialibrary_configuration['currency'] . "';\n";
                $settings .= "\$medialibrary_configuration['price_format']='" 
                  . $medialibrary_configuration['price_format'] . "';\n";
//*************************   owners list  *************
        $settings .= "// ownerslist settings\n";
        $settings .= "\$medialibrary_configuration['ownerslist']['show']='" 
                  . $medialibrary_configuration['ownerslist']['show'] ."';\n";
        $settings .= "\$medialibrary_configuration['ownerslist']['registrationlevel']='"  
                     . $medialibrary_configuration['ownerslist']['registrationlevel'] ."';\n";
//*************************   end owners list *************
        $settings .= "\$medialibrary_configuration['date_format']='" 
                  . $medialibrary_configuration['date_format'] ."';\n";
        $settings .= "\$medialibrary_configuration['datetime_format']='" 
                  . $medialibrary_configuration['datetime_format'] ."';\n";
        $settings .= "\$medialibrary_configuration['allowed_exts']='" 
                  . $medialibrary_configuration['allowed_exts'] ."';\n";
    $settings .= "\$medialibrary_configuration['allowed_exts_img']='" 
                  . $medialibrary_configuration['allowed_exts_img'] ."';\n";

    $settings .= "\$medialibrary_configuration['allowed_exts_video']='" 
                  . $medialibrary_configuration['allowed_exts_video'] ."';\n";
    $settings .= "\$medialibrary_configuration['allowed_exts_track']='" 
                  . $medialibrary_configuration['allowed_exts_track'] ."';\n";
    $settings .= "\$medialibrary_configuration['allowed_exts_audio']='" 
                  . $medialibrary_configuration['allowed_exts_audio'] ."';\n";


        $settings .= "//sale_separator\n";
                $settings .= "\$medialibrary_configuration['sale_separator']='" 
                  . $medialibrary_configuration['sale_separator'] . "';\n";
                $settings .= "?>\n";

        // Write out new initialization file
        $fd = fopen("./components/com_medialibrary/admin.medialibrary.class.conf.php", "w" )
        or die ("Cannot create configuration file.");
        fwrite( $fd, $settings );
        fclose( $fd );
    }

    /**
     * Rating Array
     * @return array an Array containing the information of all Rating
     * possibilities
     */
    static function getRatingArray(){
        $i = 0;
        $retVal = array();
        while($i < 5){
            //erster teil x,0
            $tmp = $i * 2;
            array_push($retVal, array($tmp, $i.",0"));
            //zweiter teil x,5
            $tmp ++;
            array_push($retVal, array($tmp, $i.",5"));
            $i ++;
        }
        array_push($retVal, array(10, "10,0"));
        return $retVal;
    }

    /**
     * Language Array - defined in the language files!
     * @return array an Array containing the information of all Language
     * possibilities
     */
    static function getLanguageArray(){
        $retVal = array();
        array_push($retVal, array("Not specified", _MEDIALIBRARY_LANGUAGE_NOT_USED));
        array_push($retVal, array("Dutch", _MEDIALIBRARY_LANGUAGE_DUT));
        array_push($retVal, array("English", _MEDIALIBRARY_LANGUAGE_ENG));
        array_push($retVal, array("French", _MEDIALIBRARY_LANGUAGE_FRE));
        array_push($retVal, array("German", _MEDIALIBRARY_LANGUAGE_GER));
        array_push($retVal, array("Hungarian", _MEDIALIBRARY_LANGUAGE_HU));
        array_push($retVal, array("Italian", _MEDIALIBRARY_LANGUAGE_ITA));
        array_push($retVal, array("Russian", _MEDIALIBRARY_LANGUAGE_RUS));
        array_push($retVal, array("Serbian", _MEDIALIBRARY_LANGUAGE_SRB));
        array_push($retVal, array("Spanish",_MEDIALIBRARY_LANGUAGE_SPA));

        return $retVal;
    }

    //типы мультимедии
    static function getTypeArray()
    {
        $type_list = array();
        array_push($type_list, array("book", _MEDIALIBRARY_LABEL_MEDIA_TYPE_BOOK));
        array_push($type_list, array("video", _MEDIALIBRARY_LABEL_MEDIA_TYPE_VIDEO));
        array_push($type_list, array("music", _MEDIALIBRARY_LABEL_MEDIA_TYPE_MUSIC));
        array_push($type_list, array("game", _MEDIALIBRARY_LABEL_MEDIA_TYPE_GAME));
        return $type_list;
    }

    /**
     * fetches the information from the imageURL field of the media and stores
     * the media with the ISBN number in the defined folder - then overwrites
     * the information in the imageURL field so that it points to the file
     * downloaded
     * @param mosMediaLibrary store the media with all necessary information.
     * @return null if everything is OK, else return error string
     */
    static function storeImageFile(& $media_parent,& $media, $picture){
        global $database,$mosConfig_live_site, $mosConfig_absolute_path, $medialibrary_configuration;
        $asin_or_isbn = 0;
        if(isset($media->asin)){
            $asin_or_isbn = $media->asin;
        }else{
            $asin_or_isbn = $media->isbn;
        }
        $old_pic=$media->imageURL;

        //set path for local host images files
        $is_local_url = false ;
        if(substr($old_pic,0,4) != "http")
        {
            $old_pic = $mosConfig_live_site . '/'. $old_pic;
            $is_local_url = true;
        }

    $id = $media_parent->id;
    if( $id == 0 ) {
    $database->setQuery("select max(id) as id from #__medialibrary");
    $ids = $database->loadObjectList();
    $id = $ids[0]->id + 1 ;
    }

        if ($picture != null)
        {

           $expl    = explode('.', $picture['name']);
           $ext      = $expl[count($expl)-1];
           $rnd      = substr(md5(time()),-8);
           $new_pic  = $asin_or_isbn  .'_'.$rnd . '.'.$ext;

        if( substr(    $new_pic ,-1, 1  ) == "/"){
               $len      = strlen( $new_pic  );
               $len      = $len - 1;
            $new_pic  = substr($new_pic ,0,  $len  );

            }

            if(!move_uploaded_file($picture['tmp_name'], $mosConfig_absolute_path.$medialibrary_configuration[
                'fetchImages']['location']  
                    .$new_pic))
            {
                return "Error moving File!";
            } else
            {
                $media->imageURL=$medialibrary_configuration['fetchImages']['location'].$new_pic;return null;
                //print_r($media->imageURL);exit;
            }

        }
    else if( $is_local_url){
            //for local images - do only check
            if( !($ch = curl_init($old_pic)) ) return "Bad path to image file: $old_pic";

            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_FAILONERROR, 1);
            curl_exec($ch);
            $intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);

            if ($intReturnCode != 200){
                return "Bad path image file";
            }

        }else if( !$is_local_url && strlen(trim($old_pic)) > 0){

           $expl    = explode('.', $old_pic);
           $ext      = $expl[count($expl)-1];
           $rnd      = substr(md5(time()),-8);
           $new_pic  = $asin_or_isbn  .'_'.$rnd . '.'.$ext;

        if( substr(    $new_pic ,-1, 1  ) == "/"){
               $len      = strlen( $new_pic  );
               $len      = $len - 1;
            $new_pic  = substr($new_pic ,0,  $len  );

            }

            if( strrchr($new_pic, "/") ) return "Bad path to image file: $media->imageURL";

            if( !($ch = curl_init($old_pic)) ) return "Bad path to image file: $old_pic";

            if($fp = fopen($mosConfig_absolute_path.$medialibrary_configuration['fetchImages']['location'] 
                . $new_pic, "w") ){

                curl_setopt($ch, CURLOPT_FILE, $fp);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_FAILONERROR, 1);

                curl_exec($ch);
                $intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                curl_close($ch);
                fclose($fp);

                if ($intReturnCode != 200)
                {
                    unlink($mosConfig_absolute_path .$medialibrary_configuration['fetchImages']['location']
                        .$new_pic);
                    return "Bad path image file";
                }
            }
            else
            {
                 return "Folder".$medialibrary_configuration['fetchImages']['location']."dont exist";

            }
        }else{
          return "Bad path or access deny to save image file";
        }
    }

    static function storeImageFileAuthor(&$row, $picture, $max_id) {
        global $mosConfig_live_site, $mosConfig_absolute_path, $medialibrary_configuration;
        $old_pic = $row->imageURL;
       // print_r($row->imageURL);exit;
        //set path for local host images files
        $is_local_url = false;
        if (substr($old_pic, 0, 4) != "http") {
            $old_pic = $mosConfig_live_site . '/' . $old_pic;
            $is_local_url = true;
        }
        if ($picture != null) {
            $expl = explode('.', $picture['name']);
            $ext = $expl[count($expl) - 1];
            $rnd = substr(md5(time()), -8);
            if (!empty($row->isbn)) {
                $new_pic = $row->isbn . '_' . $rnd . '.' . $ext;
            } else {
                $new_pic = $max_id . '_' . $rnd . '.' . $ext;
            }
            //$new_pic = substr($book->isbn . strrchr($picture['name'], "."), 1);
            if (!move_uploaded_file($picture['tmp_name'], $mosConfig_absolute_path . $medialibrary_configuration[
                'fetchImages']['location']   
                    . $new_pic)) {
                return "Error moving File!";
            } else {
                $row->imageURL = $medialibrary_configuration['fetchImages']['location'] . $new_pic;
                return null;
            }
        }else{
          return "Bad path or access deny to save image file";
        }
    }
}
